WordPress at Your Fingertips
class is not described

Automattic\WooCommerce

Container{} WC 1.0

PSR11 compliant dependency injection container for WooCommerce.

Classes in the src directory should specify dependencies from that directory via an 'init' method having arguments with type hints. If an instance of the container itself is needed, the type hint to use is \Psr\Container\ContainerInterface.

Classes in the src directory should interact with anything outside (especially code in the includes directory and WordPress functions) by using the classes in the Proxies directory. The exception is idempotent functions (e.g. wp_parse_url), those can be used directly.

Classes in the includes directory should use the wc_get_container function to get the instance of the container when they need to get an instance of a class from the src directory.

Class registration should be done via service providers that inherit from Automattic\WooCommerce\Internal\DependencyManagement and those should go in the src\Internal\DependencyManagement\ServiceProviders folder unless there's a good reason to put them elsewhere. All the service provider class names must be in the SERVICE_PROVIDERS constant.

No Hooks.

Return

null. Nothing.

Usage

$Container = new Container();
// use class methods

Methods

  1. __construct()
  2. ERROR: no method name found on line ` */`
  3. ERROR: no method name found on line ``
  4. ERROR: no method name found on line ` * @var \League\Container\Container`
  5. ERROR: no method name found on line ` */`
  6. ERROR: no method name found on line ``
  7. ERROR: no method name found on line ` */`
  8. ERROR: no method name found on line ``
  9. get( $id )
  10. ERROR: no method name found on line ``
  11. ERROR: no method name found on line ``
  12. ERROR: no method name found on line ``
  13. ERROR: no method name found on line ``
  14. ERROR: no method name found on line ` );`
  15. ERROR: no method name found on line ` /**`
  16. ERROR: no method name found on line ``
  17. ERROR: no method name found on line ``
  18. ERROR: no method name found on line ` *`
  19. ERROR: no method name found on line ` /**`
  20. ERROR: no method name found on line ``
  21. ERROR: no method name found on line ` /**`
  22. ERROR: no method name found on line ``
  23. has( $id )
  24. ERROR: no method name found on line ``
  25. ERROR: no method name found on line ``
  26. ERROR: no method name found on line ``
  27. ERROR: no method name found on line ``
  28. ERROR: no method name found on line ``
  29. ERROR: no method name found on line ``
  30. ERROR: no method name found on line ``
  31. ERROR: no method name found on line ``
  32. ERROR: no method name found on line ` }`
  33. ERROR: no method name found on line ` *`
  34. ERROR: no method name found on line ` }`
  35. ERROR: no method name found on line ` }`
  36. ERROR: no method name found on line ` *`
  37. ERROR: no method name found on line ` *`
  38. ERROR: no method name found on line ` }`
  39. foreach ( $this->service_providers as $service_provider_class )
  40. ERROR: no method name found on line ` }`

Code of Container{} WC 5.5.2

<?php
final class Container implements \Psr\Container\ContainerInterface {
	/**
	 * The list of service provider classes to register.
	 *
	 * @var string[]
	 */
	private $service_providers = array(
		AssignDefaultCategoryServiceProvider::class,
		DownloadPermissionsAdjusterServiceProvider::class,
		ProductAttributesLookupServiceProvider::class,
		ProxiesServiceProvider::class,
		RestockRefundedItemsAdjusterServiceProvider::class,
	);

	/**
	 * The underlying container.
	 *
	 * @var \League\Container\Container
	 */
	private $container;

	/**
	 * Class constructor.
	 */
	public function __construct() {
		$this->container = new ExtendedContainer();

		// Add ourselves as the shared instance of ContainerInterface,
		// register everything else using service providers.

		$this->container->share( \Psr\Container\ContainerInterface::class, $this );

		foreach ( $this->service_providers as $service_provider_class ) {
			$this->container->addServiceProvider( $service_provider_class );
		}
	}

	/**
	 * Finds an entry of the container by its identifier and returns it.
	 *
	 * @param string $id Identifier of the entry to look for.
	 *
	 * @throws NotFoundExceptionInterface  No entry was found for **this** identifier.
	 * @throws Psr\Container\ContainerExceptionInterface Error while retrieving the entry.
	 *
	 * @return mixed Entry.
	 */
	public function get( $id ) {
		return $this->container->get( $id );
	}

	/**
	 * Returns true if the container can return an entry for the given identifier.
	 * Returns false otherwise.
	 *
	 * `has($id)` returning true does not mean that `get($id)` will not throw an exception.
	 * It does however mean that `get($id)` will not throw a `NotFoundExceptionInterface`.
	 *
	 * @param string $id Identifier of the entry to look for.
	 *
	 * @return bool
	 */
	public function has( $id ) {
		return $this->container->has( $id );
	}
}