get an instance of class '$class_name', which doesn't exist." ); } // Account for the containers used by the Store API and Blocks. if ( StringUtil::starts_with( $class_name, 'Automattic\WooCommerce\StoreApi\\' ) ) { return StoreApi::container()->get( $class_name ); } if ( StringUtil::starts_with( $class_name, 'Automattic\WooCommerce\Blocks\\' ) ) { return BlocksPackage::container()->get( $class_name ); } $resolve_chain[] = $class_name; try { $instance = $this->instantiate_class_using_reflection( $class_name, $resolve_chain ); } catch ( \ReflectionException $e ) { throw new ContainerException( "Reflection error when resolving '$class_name': (" . get_class( $e ) . ") {$e->getMessage()}", 0, $e ); } // phpcs:enable WordPress.Security.EscapeOutput.ExceptionNotEscaped $this->resolved_cache[ $class_name ] = $instance; return $instance; } // phpcs:disable Squiz.Commenting.FunctionCommentThrowTag.WrongNumber /** * Get an instance of a class using reflection. * This method recursively calls 'get_core' (which in turn calls this method) for each of the arguments * in the 'init' method of the resolved class (if the method is public and non-static). * * @param string $class_name The name of the class to resolve. * @param array $resolve_chain Classes already resolved in this resolution chain. Passed between recursive calls to the method in order to detect a recursive resolution condition. * @return object The resolved object. * * @throws ContainerException The 'init' method has invalid arguments. * @throws \ReflectionException Something went wrong when using reflection to get information about the class to resolve. */ private function instantiate_class_using_reflection( string $class_name, array &$resolve_chain ): object { $ref_class = new \ReflectionClass( $class_name ); // phpcs:disable WordPress.Security.EscapeOutput.ExceptionNotEscaped $constructor = $ref_class->getConstructor(); if ( ! is_null( $constructor ) ) { if ( ! $constructor->isPublic() ) { throw new ContainerException( "Error resolving '$class_name': the class doesn't have a public constructor." ); } $constructor_arguments = $constructor->getParameters(); foreach ( $constructor_arguments as $argument ) { if ( ! $argument->isOptional() ) { throw new ContainerException( "Error resolving '$class_name': the class constructor has non-optional arguments." ); } } } $instance = $ref_class->newInstance(); if ( ! $ref_class->hasMethod( 'init' ) ) { return $instance; } $init_method = $ref_class->getMethod( 'init' ); if ( ! $init_method->isPublic() || $init_method->isStatic() ) { return $instance; } $init_args = $init_method->getParameters(); $init_arg_instances = array_map( function ( \ReflectionParameter $arg ) use ( $class_name, &$resolve_chain ) { $arg_type = $arg->getType(); if ( ! ( $arg_type instanceof \ReflectionNamedType ) ) { throw new ContainerException( "Error resolving '$class_name': argument '\${$arg->getName()}' doesn't have a type declaration." ); } if ( $arg_type->isBuiltin() ) { throw new ContainerException( "Error resolving '$class_name': argument '\${$arg->getName()}' is not of a class type." ); } if ( $arg->isPassedByReference() ) { throw new ContainerException( "Error resolving '$class_name': argument '\${$arg->getName()}' is passed by reference." ); } return $this->get_core( $arg_type->getName(), $resolve_chain ); }, $init_args ); // phpcs:enable WordPress.Security.EscapeOutput.ExceptionNotEscaped $init_method->invoke( $instance, ...$init_arg_instances ); return $instance; } // phpcs:enable Squiz.Commenting.FunctionCommentThrowTag.WrongNumber /** * Tells if the 'get' method can be used to resolve a given class. * * Note that 'get' can throw an exception even if this method returns true, * for example for classes that are in the correct namespace but don't have a public constructor. * * @param string $class_name The class name. * @return bool True if the class with the supplied name can be resolved with 'get'. */ public function has( string $class_name ): bool { $class_name = trim( $class_name, '\\' ); return $this->is_class_allowed( $class_name ) || isset( $this->resolved_cache[ $class_name ] ); } /** * Checks to see whether a class is allowed to be registered. * * @param string $class_name The class to check. * * @return bool True if the class is allowed to be registered, false otherwise. */ protected function is_class_allowed( string $class_name ): bool { return StringUtil::starts_with( $class_name, self::WOOCOMMERCE_NAMESPACE, false ); } } 1 - Uncaught Error: Class 'Automattic\WooCommerce\Internal\DependencyManagement\RuntimeContainer' not found in /home/st20space2tech/public_html/site/wp-content/plugins/woocommerce/src/Container.php:46 Stack trace: #0 /home/st20space2tech/public_html/site/wp-content/plugins/woocommerce/woocommerce.php(38): Automattic\WooCommerce\Container->__construct() #1 /home/st20space2tech/public_html/site/wp-settings.php(589): include_once('/home/st20space...') #2 /home/st20space2tech/public_html/site/wp-config.php(92): require_once('/home/st20space...') #3 /home/st20space2tech/public_html/site/wp-load.php(50): require_once('/home/st20space...') #4 /home/st20space2tech/public_html/site/wp-blog-header.php(13): require_once('/home/st20space...') #5 /home/st20space2tech/public_html/site/index.php(17): require('/home/st20space...') #6 {main} thrown - /home/st20space2tech/public_html/site/wp-content/plugins/woocommerce/src/Container.php - 46