Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/woocomme.../src
File: Container.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Container class file.
[2] Fix | Delete
*/
[3] Fix | Delete
[4] Fix | Delete
declare( strict_types=1 );
[5] Fix | Delete
[6] Fix | Delete
namespace Automattic\WooCommerce;
[7] Fix | Delete
[8] Fix | Delete
use Automattic\WooCommerce\Internal\DependencyManagement\ContainerException;
[9] Fix | Delete
use Automattic\WooCommerce\Internal\DependencyManagement\RuntimeContainer;
[10] Fix | Delete
[11] Fix | Delete
/**
[12] Fix | Delete
* PSR11 compliant dependency injection container for WooCommerce.
[13] Fix | Delete
*
[14] Fix | Delete
* Classes in the `src` directory should specify dependencies from that directory via an 'init' method having arguments
[15] Fix | Delete
* with type hints. If an instance of the container itself is needed, the type hint to use is \Psr\Container\ContainerInterface.
[16] Fix | Delete
*
[17] Fix | Delete
* Classes in the `src` directory should interact with anything outside (especially code in the `includes` directory
[18] Fix | Delete
* and WordPress functions) by using the classes in the `Proxies` directory. The exception is idempotent
[19] Fix | Delete
* functions (e.g. `wp_parse_url`), those can be used directly.
[20] Fix | Delete
*
[21] Fix | Delete
* Classes in the `includes` directory should use the `wc_get_container` function to get the instance of the container when
[22] Fix | Delete
* they need to get an instance of a class from the `src` directory.
[23] Fix | Delete
*
[24] Fix | Delete
* Internally, an instance of RuntimeContainer will be used for the actual class resolution. This class uses reflection
[25] Fix | Delete
* to instantiate classes and figure out dependencies, so there's no need for explicit class registration.
[26] Fix | Delete
* When running the unit tests suite this will be replaced with an instance of TestingContainer,
[27] Fix | Delete
* which provides additional functionality.
[28] Fix | Delete
*/
[29] Fix | Delete
final class Container {
[30] Fix | Delete
/**
[31] Fix | Delete
* The underlying container.
[32] Fix | Delete
*
[33] Fix | Delete
* @var RuntimeContainer
[34] Fix | Delete
*/
[35] Fix | Delete
private $container;
[36] Fix | Delete
[37] Fix | Delete
/**
[38] Fix | Delete
* Class constructor.
[39] Fix | Delete
*/
[40] Fix | Delete
public function __construct() {
[41] Fix | Delete
// When the League container was in use we allowed to retrieve the container itself
[42] Fix | Delete
// by using 'Psr\Container\ContainerInterface' as the class identifier,
[43] Fix | Delete
// we continue allowing that for compatibility.
[44] Fix | Delete
$this->container = new RuntimeContainer(
[45] Fix | Delete
array(
[46] Fix | Delete
__CLASS__ => $this,
[47] Fix | Delete
'Psr\Container\ContainerInterface' => $this,
[48] Fix | Delete
)
[49] Fix | Delete
);
[50] Fix | Delete
}
[51] Fix | Delete
[52] Fix | Delete
/**
[53] Fix | Delete
* Returns an instance of the specified class.
[54] Fix | Delete
* See the comment about ContainerException in RuntimeContainer::get.
[55] Fix | Delete
*
[56] Fix | Delete
* @param string $id Class name.
[57] Fix | Delete
*
[58] Fix | Delete
* @return object Object instance.
[59] Fix | Delete
*
[60] Fix | Delete
* @throws ContainerException Error when resolving the class to an object instance, or class not found.
[61] Fix | Delete
* @throws \Exception Exception thrown in the constructor or in the 'init' method of one of the resolved classes.
[62] Fix | Delete
*/
[63] Fix | Delete
public function get( string $id ) {
[64] Fix | Delete
return $this->container->get( $id );
[65] Fix | Delete
}
[66] Fix | Delete
[67] Fix | Delete
/**
[68] Fix | Delete
* Returns true if the container can return an instance of the given class or false otherwise.
[69] Fix | Delete
* See the comment in RuntimeContainer::has.
[70] Fix | Delete
*
[71] Fix | Delete
* @param class-string $id Class name.
[72] Fix | Delete
*
[73] Fix | Delete
* @return bool
[74] Fix | Delete
*/
[75] Fix | Delete
public function has( string $id ): bool {
[76] Fix | Delete
return $this->container->has( $id );
[77] Fix | Delete
}
[78] Fix | Delete
}
[79] Fix | Delete
[80] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function