woocommerce/src/Container.php

98 lines
3.2 KiB
PHP
Raw Normal View History

<?php
/**
Changes in the overall organization of the dependency injection: - The `Container` class now implements `Psr\Container\ContainerInterface` (and registers itself as such), holding a private instance of the real container. This way it's a read-only container from the point of view of plugins (which should use their own containers, but can still use this to get WooCommerce classes). - All registrations are now done in the `Container` constructor via service providers. - The container instance is now held in a global variable, set in `woocommerce.php` - Added the `wc_get_container` function for old code. - Added the `AbstractServiceProvider` class, which inherits with the corresponding League's class and adds some utility methods, most notably `add/shareWithAutoArguments`. - Added the `ActionsProxy` and `LegacyProxy` classes, they are registered via a dedicated service provider. - `WC_Queue_Interface` is no longer resolvable via the container (which is for classes inside `src` only). - All the method names in the new classes have the format `fooBarFizz` to be PSR4 compliant, so the MethodNameInvalid error has been disabled in phpcs.xml for the `src` directory. - Introduced the `@public` annotation for public API classes (classes that plugins can use and whose backwards compatibility we guarantee), applied to `ActionsProxy` and to `LegacyProxy` for now. - Removed the hack for the autoloader as now it doesn't work anyway. For the changes in this branch to work, now WP_DEBUG must be false.
2020-06-18 12:15:08 +00:00
* Container class file.
*
Changes in the overall organization of the dependency injection: - The `Container` class now implements `Psr\Container\ContainerInterface` (and registers itself as such), holding a private instance of the real container. This way it's a read-only container from the point of view of plugins (which should use their own containers, but can still use this to get WooCommerce classes). - All registrations are now done in the `Container` constructor via service providers. - The container instance is now held in a global variable, set in `woocommerce.php` - Added the `wc_get_container` function for old code. - Added the `AbstractServiceProvider` class, which inherits with the corresponding League's class and adds some utility methods, most notably `add/shareWithAutoArguments`. - Added the `ActionsProxy` and `LegacyProxy` classes, they are registered via a dedicated service provider. - `WC_Queue_Interface` is no longer resolvable via the container (which is for classes inside `src` only). - All the method names in the new classes have the format `fooBarFizz` to be PSR4 compliant, so the MethodNameInvalid error has been disabled in phpcs.xml for the `src` directory. - Introduced the `@public` annotation for public API classes (classes that plugins can use and whose backwards compatibility we guarantee), applied to `ActionsProxy` and to `LegacyProxy` for now. - Removed the hack for the autoloader as now it doesn't work anyway. For the changes in this branch to work, now WP_DEBUG must be false.
2020-06-18 12:15:08 +00:00
* @package Automattic\WooCommerce
*/
namespace Automattic\WooCommerce;
use Automattic\WooCommerce\DependencyManagement\ServiceProviders\ProxiesServiceProvider;
use Automattic\WooCommerce\DependencyManagement\ExtendedContainer;
/**
Changes in the overall organization of the dependency injection: - The `Container` class now implements `Psr\Container\ContainerInterface` (and registers itself as such), holding a private instance of the real container. This way it's a read-only container from the point of view of plugins (which should use their own containers, but can still use this to get WooCommerce classes). - All registrations are now done in the `Container` constructor via service providers. - The container instance is now held in a global variable, set in `woocommerce.php` - Added the `wc_get_container` function for old code. - Added the `AbstractServiceProvider` class, which inherits with the corresponding League's class and adds some utility methods, most notably `add/shareWithAutoArguments`. - Added the `ActionsProxy` and `LegacyProxy` classes, they are registered via a dedicated service provider. - `WC_Queue_Interface` is no longer resolvable via the container (which is for classes inside `src` only). - All the method names in the new classes have the format `fooBarFizz` to be PSR4 compliant, so the MethodNameInvalid error has been disabled in phpcs.xml for the `src` directory. - Introduced the `@public` annotation for public API classes (classes that plugins can use and whose backwards compatibility we guarantee), applied to `ActionsProxy` and to `LegacyProxy` for now. - Removed the hack for the autoloader as now it doesn't work anyway. For the changes in this branch to work, now WP_DEBUG must be false.
2020-06-18 12:15:08 +00:00
* PSR11 compliant dependency injection container for WooCommerce.
*
Changes in the overall organization of the dependency injection: - The `Container` class now implements `Psr\Container\ContainerInterface` (and registers itself as such), holding a private instance of the real container. This way it's a read-only container from the point of view of plugins (which should use their own containers, but can still use this to get WooCommerce classes). - All registrations are now done in the `Container` constructor via service providers. - The container instance is now held in a global variable, set in `woocommerce.php` - Added the `wc_get_container` function for old code. - Added the `AbstractServiceProvider` class, which inherits with the corresponding League's class and adds some utility methods, most notably `add/shareWithAutoArguments`. - Added the `ActionsProxy` and `LegacyProxy` classes, they are registered via a dedicated service provider. - `WC_Queue_Interface` is no longer resolvable via the container (which is for classes inside `src` only). - All the method names in the new classes have the format `fooBarFizz` to be PSR4 compliant, so the MethodNameInvalid error has been disabled in phpcs.xml for the `src` directory. - Introduced the `@public` annotation for public API classes (classes that plugins can use and whose backwards compatibility we guarantee), applied to `ActionsProxy` and to `LegacyProxy` for now. - Removed the hack for the autoloader as now it doesn't work anyway. For the changes in this branch to work, now WP_DEBUG must be false.
2020-06-18 12:15:08 +00:00
* Classes in the `src` directory should specify dependencies from that directory via constructor arguments
* with type hints. If an instance of the container itself is needed, the type hint to use is \Psr\Container\ContainerInterface.
*
Changes in the overall organization of the dependency injection: - The `Container` class now implements `Psr\Container\ContainerInterface` (and registers itself as such), holding a private instance of the real container. This way it's a read-only container from the point of view of plugins (which should use their own containers, but can still use this to get WooCommerce classes). - All registrations are now done in the `Container` constructor via service providers. - The container instance is now held in a global variable, set in `woocommerce.php` - Added the `wc_get_container` function for old code. - Added the `AbstractServiceProvider` class, which inherits with the corresponding League's class and adds some utility methods, most notably `add/shareWithAutoArguments`. - Added the `ActionsProxy` and `LegacyProxy` classes, they are registered via a dedicated service provider. - `WC_Queue_Interface` is no longer resolvable via the container (which is for classes inside `src` only). - All the method names in the new classes have the format `fooBarFizz` to be PSR4 compliant, so the MethodNameInvalid error has been disabled in phpcs.xml for the `src` directory. - Introduced the `@public` annotation for public API classes (classes that plugins can use and whose backwards compatibility we guarantee), applied to `ActionsProxy` and to `LegacyProxy` for now. - Removed the hack for the autoloader as now it doesn't work anyway. For the changes in this branch to work, now WP_DEBUG must be false.
2020-06-18 12:15:08 +00:00
* 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.
*
Changes in the overall organization of the dependency injection: - The `Container` class now implements `Psr\Container\ContainerInterface` (and registers itself as such), holding a private instance of the real container. This way it's a read-only container from the point of view of plugins (which should use their own containers, but can still use this to get WooCommerce classes). - All registrations are now done in the `Container` constructor via service providers. - The container instance is now held in a global variable, set in `woocommerce.php` - Added the `wc_get_container` function for old code. - Added the `AbstractServiceProvider` class, which inherits with the corresponding League's class and adds some utility methods, most notably `add/shareWithAutoArguments`. - Added the `ActionsProxy` and `LegacyProxy` classes, they are registered via a dedicated service provider. - `WC_Queue_Interface` is no longer resolvable via the container (which is for classes inside `src` only). - All the method names in the new classes have the format `fooBarFizz` to be PSR4 compliant, so the MethodNameInvalid error has been disabled in phpcs.xml for the `src` directory. - Introduced the `@public` annotation for public API classes (classes that plugins can use and whose backwards compatibility we guarantee), applied to `ActionsProxy` and to `LegacyProxy` for now. - Removed the hack for the autoloader as now it doesn't work anyway. For the changes in this branch to work, now WP_DEBUG must be false.
2020-06-18 12:15:08 +00:00
* 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.
*
Changes in the overall organization of the dependency injection: - The `Container` class now implements `Psr\Container\ContainerInterface` (and registers itself as such), holding a private instance of the real container. This way it's a read-only container from the point of view of plugins (which should use their own containers, but can still use this to get WooCommerce classes). - All registrations are now done in the `Container` constructor via service providers. - The container instance is now held in a global variable, set in `woocommerce.php` - Added the `wc_get_container` function for old code. - Added the `AbstractServiceProvider` class, which inherits with the corresponding League's class and adds some utility methods, most notably `add/shareWithAutoArguments`. - Added the `ActionsProxy` and `LegacyProxy` classes, they are registered via a dedicated service provider. - `WC_Queue_Interface` is no longer resolvable via the container (which is for classes inside `src` only). - All the method names in the new classes have the format `fooBarFizz` to be PSR4 compliant, so the MethodNameInvalid error has been disabled in phpcs.xml for the `src` directory. - Introduced the `@public` annotation for public API classes (classes that plugins can use and whose backwards compatibility we guarantee), applied to `ActionsProxy` and to `LegacyProxy` for now. - Removed the hack for the autoloader as now it doesn't work anyway. For the changes in this branch to work, now WP_DEBUG must be false.
2020-06-18 12:15:08 +00:00
* Class registration should be done via service providers that inherit from Automattic\WooCommerce\Tools\DependencyManagement
* and those should go in the `src\Tools\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.
*/
Changes in the overall organization of the dependency injection: - The `Container` class now implements `Psr\Container\ContainerInterface` (and registers itself as such), holding a private instance of the real container. This way it's a read-only container from the point of view of plugins (which should use their own containers, but can still use this to get WooCommerce classes). - All registrations are now done in the `Container` constructor via service providers. - The container instance is now held in a global variable, set in `woocommerce.php` - Added the `wc_get_container` function for old code. - Added the `AbstractServiceProvider` class, which inherits with the corresponding League's class and adds some utility methods, most notably `add/shareWithAutoArguments`. - Added the `ActionsProxy` and `LegacyProxy` classes, they are registered via a dedicated service provider. - `WC_Queue_Interface` is no longer resolvable via the container (which is for classes inside `src` only). - All the method names in the new classes have the format `fooBarFizz` to be PSR4 compliant, so the MethodNameInvalid error has been disabled in phpcs.xml for the `src` directory. - Introduced the `@public` annotation for public API classes (classes that plugins can use and whose backwards compatibility we guarantee), applied to `ActionsProxy` and to `LegacyProxy` for now. - Removed the hack for the autoloader as now it doesn't work anyway. For the changes in this branch to work, now WP_DEBUG must be false.
2020-06-18 12:15:08 +00:00
final class Container implements \Psr\Container\ContainerInterface {
/**
* The root namespace of all WooCommerce classes in the `src` directory.
*/
const WOOCOMMERCE_ROOT_NAMESPACE = 'Automattic\\WooCommerce';
/**
Changes in the overall organization of the dependency injection: - The `Container` class now implements `Psr\Container\ContainerInterface` (and registers itself as such), holding a private instance of the real container. This way it's a read-only container from the point of view of plugins (which should use their own containers, but can still use this to get WooCommerce classes). - All registrations are now done in the `Container` constructor via service providers. - The container instance is now held in a global variable, set in `woocommerce.php` - Added the `wc_get_container` function for old code. - Added the `AbstractServiceProvider` class, which inherits with the corresponding League's class and adds some utility methods, most notably `add/shareWithAutoArguments`. - Added the `ActionsProxy` and `LegacyProxy` classes, they are registered via a dedicated service provider. - `WC_Queue_Interface` is no longer resolvable via the container (which is for classes inside `src` only). - All the method names in the new classes have the format `fooBarFizz` to be PSR4 compliant, so the MethodNameInvalid error has been disabled in phpcs.xml for the `src` directory. - Introduced the `@public` annotation for public API classes (classes that plugins can use and whose backwards compatibility we guarantee), applied to `ActionsProxy` and to `LegacyProxy` for now. - Removed the hack for the autoloader as now it doesn't work anyway. For the changes in this branch to work, now WP_DEBUG must be false.
2020-06-18 12:15:08 +00:00
* The list of service provider classes to register.
*
Changes in the overall organization of the dependency injection: - The `Container` class now implements `Psr\Container\ContainerInterface` (and registers itself as such), holding a private instance of the real container. This way it's a read-only container from the point of view of plugins (which should use their own containers, but can still use this to get WooCommerce classes). - All registrations are now done in the `Container` constructor via service providers. - The container instance is now held in a global variable, set in `woocommerce.php` - Added the `wc_get_container` function for old code. - Added the `AbstractServiceProvider` class, which inherits with the corresponding League's class and adds some utility methods, most notably `add/shareWithAutoArguments`. - Added the `ActionsProxy` and `LegacyProxy` classes, they are registered via a dedicated service provider. - `WC_Queue_Interface` is no longer resolvable via the container (which is for classes inside `src` only). - All the method names in the new classes have the format `fooBarFizz` to be PSR4 compliant, so the MethodNameInvalid error has been disabled in phpcs.xml for the `src` directory. - Introduced the `@public` annotation for public API classes (classes that plugins can use and whose backwards compatibility we guarantee), applied to `ActionsProxy` and to `LegacyProxy` for now. - Removed the hack for the autoloader as now it doesn't work anyway. For the changes in this branch to work, now WP_DEBUG must be false.
2020-06-18 12:15:08 +00:00
* @var string[]
*/
Changes in the overall organization of the dependency injection: - The `Container` class now implements `Psr\Container\ContainerInterface` (and registers itself as such), holding a private instance of the real container. This way it's a read-only container from the point of view of plugins (which should use their own containers, but can still use this to get WooCommerce classes). - All registrations are now done in the `Container` constructor via service providers. - The container instance is now held in a global variable, set in `woocommerce.php` - Added the `wc_get_container` function for old code. - Added the `AbstractServiceProvider` class, which inherits with the corresponding League's class and adds some utility methods, most notably `add/shareWithAutoArguments`. - Added the `ActionsProxy` and `LegacyProxy` classes, they are registered via a dedicated service provider. - `WC_Queue_Interface` is no longer resolvable via the container (which is for classes inside `src` only). - All the method names in the new classes have the format `fooBarFizz` to be PSR4 compliant, so the MethodNameInvalid error has been disabled in phpcs.xml for the `src` directory. - Introduced the `@public` annotation for public API classes (classes that plugins can use and whose backwards compatibility we guarantee), applied to `ActionsProxy` and to `LegacyProxy` for now. - Removed the hack for the autoloader as now it doesn't work anyway. For the changes in this branch to work, now WP_DEBUG must be false.
2020-06-18 12:15:08 +00:00
private $service_providers = array(
ProxiesServiceProvider::class,
Changes in the overall organization of the dependency injection: - The `Container` class now implements `Psr\Container\ContainerInterface` (and registers itself as such), holding a private instance of the real container. This way it's a read-only container from the point of view of plugins (which should use their own containers, but can still use this to get WooCommerce classes). - All registrations are now done in the `Container` constructor via service providers. - The container instance is now held in a global variable, set in `woocommerce.php` - Added the `wc_get_container` function for old code. - Added the `AbstractServiceProvider` class, which inherits with the corresponding League's class and adds some utility methods, most notably `add/shareWithAutoArguments`. - Added the `ActionsProxy` and `LegacyProxy` classes, they are registered via a dedicated service provider. - `WC_Queue_Interface` is no longer resolvable via the container (which is for classes inside `src` only). - All the method names in the new classes have the format `fooBarFizz` to be PSR4 compliant, so the MethodNameInvalid error has been disabled in phpcs.xml for the `src` directory. - Introduced the `@public` annotation for public API classes (classes that plugins can use and whose backwards compatibility we guarantee), applied to `ActionsProxy` and to `LegacyProxy` for now. - Removed the hack for the autoloader as now it doesn't work anyway. For the changes in this branch to work, now WP_DEBUG must be false.
2020-06-18 12:15:08 +00:00
);
/**
Changes in the overall organization of the dependency injection: - The `Container` class now implements `Psr\Container\ContainerInterface` (and registers itself as such), holding a private instance of the real container. This way it's a read-only container from the point of view of plugins (which should use their own containers, but can still use this to get WooCommerce classes). - All registrations are now done in the `Container` constructor via service providers. - The container instance is now held in a global variable, set in `woocommerce.php` - Added the `wc_get_container` function for old code. - Added the `AbstractServiceProvider` class, which inherits with the corresponding League's class and adds some utility methods, most notably `add/shareWithAutoArguments`. - Added the `ActionsProxy` and `LegacyProxy` classes, they are registered via a dedicated service provider. - `WC_Queue_Interface` is no longer resolvable via the container (which is for classes inside `src` only). - All the method names in the new classes have the format `fooBarFizz` to be PSR4 compliant, so the MethodNameInvalid error has been disabled in phpcs.xml for the `src` directory. - Introduced the `@public` annotation for public API classes (classes that plugins can use and whose backwards compatibility we guarantee), applied to `ActionsProxy` and to `LegacyProxy` for now. - Removed the hack for the autoloader as now it doesn't work anyway. For the changes in this branch to work, now WP_DEBUG must be false.
2020-06-18 12:15:08 +00:00
* The underlying container.
*
* @var \League\Container\Container
Changes in the overall organization of the dependency injection: - The `Container` class now implements `Psr\Container\ContainerInterface` (and registers itself as such), holding a private instance of the real container. This way it's a read-only container from the point of view of plugins (which should use their own containers, but can still use this to get WooCommerce classes). - All registrations are now done in the `Container` constructor via service providers. - The container instance is now held in a global variable, set in `woocommerce.php` - Added the `wc_get_container` function for old code. - Added the `AbstractServiceProvider` class, which inherits with the corresponding League's class and adds some utility methods, most notably `add/shareWithAutoArguments`. - Added the `ActionsProxy` and `LegacyProxy` classes, they are registered via a dedicated service provider. - `WC_Queue_Interface` is no longer resolvable via the container (which is for classes inside `src` only). - All the method names in the new classes have the format `fooBarFizz` to be PSR4 compliant, so the MethodNameInvalid error has been disabled in phpcs.xml for the `src` directory. - Introduced the `@public` annotation for public API classes (classes that plugins can use and whose backwards compatibility we guarantee), applied to `ActionsProxy` and to `LegacyProxy` for now. - Removed the hack for the autoloader as now it doesn't work anyway. For the changes in this branch to work, now WP_DEBUG must be false.
2020-06-18 12:15:08 +00:00
*/
private $container;
/**
* Class constructor.
*/
Changes in the overall organization of the dependency injection: - The `Container` class now implements `Psr\Container\ContainerInterface` (and registers itself as such), holding a private instance of the real container. This way it's a read-only container from the point of view of plugins (which should use their own containers, but can still use this to get WooCommerce classes). - All registrations are now done in the `Container` constructor via service providers. - The container instance is now held in a global variable, set in `woocommerce.php` - Added the `wc_get_container` function for old code. - Added the `AbstractServiceProvider` class, which inherits with the corresponding League's class and adds some utility methods, most notably `add/shareWithAutoArguments`. - Added the `ActionsProxy` and `LegacyProxy` classes, they are registered via a dedicated service provider. - `WC_Queue_Interface` is no longer resolvable via the container (which is for classes inside `src` only). - All the method names in the new classes have the format `fooBarFizz` to be PSR4 compliant, so the MethodNameInvalid error has been disabled in phpcs.xml for the `src` directory. - Introduced the `@public` annotation for public API classes (classes that plugins can use and whose backwards compatibility we guarantee), applied to `ActionsProxy` and to `LegacyProxy` for now. - Removed the hack for the autoloader as now it doesn't work anyway. For the changes in this branch to work, now WP_DEBUG must be false.
2020-06-18 12:15:08 +00:00
public function __construct() {
$this->container = new ExtendedContainer();
Changes in the overall organization of the dependency injection: - The `Container` class now implements `Psr\Container\ContainerInterface` (and registers itself as such), holding a private instance of the real container. This way it's a read-only container from the point of view of plugins (which should use their own containers, but can still use this to get WooCommerce classes). - All registrations are now done in the `Container` constructor via service providers. - The container instance is now held in a global variable, set in `woocommerce.php` - Added the `wc_get_container` function for old code. - Added the `AbstractServiceProvider` class, which inherits with the corresponding League's class and adds some utility methods, most notably `add/shareWithAutoArguments`. - Added the `ActionsProxy` and `LegacyProxy` classes, they are registered via a dedicated service provider. - `WC_Queue_Interface` is no longer resolvable via the container (which is for classes inside `src` only). - All the method names in the new classes have the format `fooBarFizz` to be PSR4 compliant, so the MethodNameInvalid error has been disabled in phpcs.xml for the `src` directory. - Introduced the `@public` annotation for public API classes (classes that plugins can use and whose backwards compatibility we guarantee), applied to `ActionsProxy` and to `LegacyProxy` for now. - Removed the hack for the autoloader as now it doesn't work anyway. For the changes in this branch to work, now WP_DEBUG must be false.
2020-06-18 12:15:08 +00:00
// Add ourselves as the shared instance of ContainerInterface,
// register everything else using service providers.
$this->container->share( \Psr\Container\ContainerInterface::class, $this );
Changes in the overall organization of the dependency injection: - The `Container` class now implements `Psr\Container\ContainerInterface` (and registers itself as such), holding a private instance of the real container. This way it's a read-only container from the point of view of plugins (which should use their own containers, but can still use this to get WooCommerce classes). - All registrations are now done in the `Container` constructor via service providers. - The container instance is now held in a global variable, set in `woocommerce.php` - Added the `wc_get_container` function for old code. - Added the `AbstractServiceProvider` class, which inherits with the corresponding League's class and adds some utility methods, most notably `add/shareWithAutoArguments`. - Added the `ActionsProxy` and `LegacyProxy` classes, they are registered via a dedicated service provider. - `WC_Queue_Interface` is no longer resolvable via the container (which is for classes inside `src` only). - All the method names in the new classes have the format `fooBarFizz` to be PSR4 compliant, so the MethodNameInvalid error has been disabled in phpcs.xml for the `src` directory. - Introduced the `@public` annotation for public API classes (classes that plugins can use and whose backwards compatibility we guarantee), applied to `ActionsProxy` and to `LegacyProxy` for now. - Removed the hack for the autoloader as now it doesn't work anyway. For the changes in this branch to work, now WP_DEBUG must be false.
2020-06-18 12:15:08 +00:00
foreach ( $this->service_providers as $service_provider_class ) {
$this->container->addServiceProvider( $service_provider_class );
}
}
Changes in the overall organization of the dependency injection: - The `Container` class now implements `Psr\Container\ContainerInterface` (and registers itself as such), holding a private instance of the real container. This way it's a read-only container from the point of view of plugins (which should use their own containers, but can still use this to get WooCommerce classes). - All registrations are now done in the `Container` constructor via service providers. - The container instance is now held in a global variable, set in `woocommerce.php` - Added the `wc_get_container` function for old code. - Added the `AbstractServiceProvider` class, which inherits with the corresponding League's class and adds some utility methods, most notably `add/shareWithAutoArguments`. - Added the `ActionsProxy` and `LegacyProxy` classes, they are registered via a dedicated service provider. - `WC_Queue_Interface` is no longer resolvable via the container (which is for classes inside `src` only). - All the method names in the new classes have the format `fooBarFizz` to be PSR4 compliant, so the MethodNameInvalid error has been disabled in phpcs.xml for the `src` directory. - Introduced the `@public` annotation for public API classes (classes that plugins can use and whose backwards compatibility we guarantee), applied to `ActionsProxy` and to `LegacyProxy` for now. - Removed the hack for the autoloader as now it doesn't work anyway. For the changes in this branch to work, now WP_DEBUG must be false.
2020-06-18 12:15:08 +00:00
/**
* 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 );
}
/**
Changes in the overall organization of the dependency injection: - The `Container` class now implements `Psr\Container\ContainerInterface` (and registers itself as such), holding a private instance of the real container. This way it's a read-only container from the point of view of plugins (which should use their own containers, but can still use this to get WooCommerce classes). - All registrations are now done in the `Container` constructor via service providers. - The container instance is now held in a global variable, set in `woocommerce.php` - Added the `wc_get_container` function for old code. - Added the `AbstractServiceProvider` class, which inherits with the corresponding League's class and adds some utility methods, most notably `add/shareWithAutoArguments`. - Added the `ActionsProxy` and `LegacyProxy` classes, they are registered via a dedicated service provider. - `WC_Queue_Interface` is no longer resolvable via the container (which is for classes inside `src` only). - All the method names in the new classes have the format `fooBarFizz` to be PSR4 compliant, so the MethodNameInvalid error has been disabled in phpcs.xml for the `src` directory. - Introduced the `@public` annotation for public API classes (classes that plugins can use and whose backwards compatibility we guarantee), applied to `ActionsProxy` and to `LegacyProxy` for now. - Removed the hack for the autoloader as now it doesn't work anyway. For the changes in this branch to work, now WP_DEBUG must be false.
2020-06-18 12:15:08 +00:00
* 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.
*
Changes in the overall organization of the dependency injection: - The `Container` class now implements `Psr\Container\ContainerInterface` (and registers itself as such), holding a private instance of the real container. This way it's a read-only container from the point of view of plugins (which should use their own containers, but can still use this to get WooCommerce classes). - All registrations are now done in the `Container` constructor via service providers. - The container instance is now held in a global variable, set in `woocommerce.php` - Added the `wc_get_container` function for old code. - Added the `AbstractServiceProvider` class, which inherits with the corresponding League's class and adds some utility methods, most notably `add/shareWithAutoArguments`. - Added the `ActionsProxy` and `LegacyProxy` classes, they are registered via a dedicated service provider. - `WC_Queue_Interface` is no longer resolvable via the container (which is for classes inside `src` only). - All the method names in the new classes have the format `fooBarFizz` to be PSR4 compliant, so the MethodNameInvalid error has been disabled in phpcs.xml for the `src` directory. - Introduced the `@public` annotation for public API classes (classes that plugins can use and whose backwards compatibility we guarantee), applied to `ActionsProxy` and to `LegacyProxy` for now. - Removed the hack for the autoloader as now it doesn't work anyway. For the changes in this branch to work, now WP_DEBUG must be false.
2020-06-18 12:15:08 +00:00
* @return bool
*/
Changes in the overall organization of the dependency injection: - The `Container` class now implements `Psr\Container\ContainerInterface` (and registers itself as such), holding a private instance of the real container. This way it's a read-only container from the point of view of plugins (which should use their own containers, but can still use this to get WooCommerce classes). - All registrations are now done in the `Container` constructor via service providers. - The container instance is now held in a global variable, set in `woocommerce.php` - Added the `wc_get_container` function for old code. - Added the `AbstractServiceProvider` class, which inherits with the corresponding League's class and adds some utility methods, most notably `add/shareWithAutoArguments`. - Added the `ActionsProxy` and `LegacyProxy` classes, they are registered via a dedicated service provider. - `WC_Queue_Interface` is no longer resolvable via the container (which is for classes inside `src` only). - All the method names in the new classes have the format `fooBarFizz` to be PSR4 compliant, so the MethodNameInvalid error has been disabled in phpcs.xml for the `src` directory. - Introduced the `@public` annotation for public API classes (classes that plugins can use and whose backwards compatibility we guarantee), applied to `ActionsProxy` and to `LegacyProxy` for now. - Removed the hack for the autoloader as now it doesn't work anyway. For the changes in this branch to work, now WP_DEBUG must be false.
2020-06-18 12:15:08 +00:00
public function has( $id ) {
return $this->container->has( $id );
}
}