WooCommerce Code Reference

Container
in package

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.

Table of Contents

$container  : Container
The underlying container.
$service_providers  : array<string|int, string>
The list of service provider classes to register.
__construct()  : mixed
Class constructor.
get()  : mixed
Finds an entry of the container by its identifier and returns it.
has()  : bool
Returns true if the container can return an entry for the given identifier.

Properties

$container

The underlying container.

private Container $container

$service_providers

The list of service provider classes to register.

private array<string|int, string> $service_providers = array(AutomatticWooCommerceInternalDependencyManagementServiceProvidersAssignDefaultCategoryServiceProvider::class, AutomatticWooCommerceInternalDependencyManagementServiceProvidersDownloadPermissionsAdjusterServiceProvider::class, AutomatticWooCommerceInternalDependencyManagementServiceProvidersOptionSanitizerServiceProvider::class, AutomatticWooCommerceInternalDependencyManagementServiceProvidersOrdersDataStoreServiceProvider::class, AutomatticWooCommerceInternalDependencyManagementServiceProvidersProductAttributesLookupServiceProvider::class, AutomatticWooCommerceInternalDependencyManagementServiceProvidersProductDownloadsServiceProvider::class, AutomatticWooCommerceInternalDependencyManagementServiceProvidersProductImageBySKUServiceProvider::class, AutomatticWooCommerceInternalDependencyManagementServiceProvidersProductReviewsServiceProvider::class, AutomatticWooCommerceInternalDependencyManagementServiceProvidersProxiesServiceProvider::class, AutomatticWooCommerceInternalDependencyManagementServiceProvidersRestockRefundedItemsAdjusterServiceProvider::class, AutomatticWooCommerceInternalDependencyManagementServiceProvidersUtilsClassesServiceProvider::class, AutomatticWooCommerceInternalDependencyManagementServiceProvidersCOTMigrationServiceProvider::class, AutomatticWooCommerceInternalDependencyManagementServiceProvidersOrdersControllersServiceProvider::class, AutomatticWooCommerceInternalDependencyManagementServiceProvidersOrderAttributionServiceProvider::class, AutomatticWooCommerceInternalDependencyManagementServiceProvidersObjectCacheServiceProvider::class, AutomatticWooCommerceInternalDependencyManagementServiceProvidersBatchProcessingServiceProvider::class, AutomatticWooCommerceInternalDependencyManagementServiceProvidersOrderMetaBoxServiceProvider::class, AutomatticWooCommerceInternalDependencyManagementServiceProvidersOrderAdminServiceProvider::class, AutomatticWooCommerceInternalDependencyManagementServiceProvidersFeaturesServiceProvider::class, AutomatticWooCommerceInternalDependencyManagementServiceProvidersMarketingServiceProvider::class, AutomatticWooCommerceInternalDependencyManagementServiceProvidersMarketplaceServiceProvider::class, AutomatticWooCommerceInternalDependencyManagementServiceProvidersLayoutTemplatesServiceProvider::class, AutomatticWooCommerceInternalDependencyManagementServiceProvidersLoggingServiceProvider::class, AutomatticWooCommerceInternalDependencyManagementServiceProvidersEnginesServiceProvider::class, AutomatticWooCommerceInternalDependencyManagementServiceProvidersComingSoonServiceProvider::class)

Methods

__construct()

Class constructor.

public __construct() : mixed
Return values
mixed

get()

Finds an entry of the container by its identifier and returns it.

public get(string $id) : mixed
Parameters
$id : string

Identifier of the entry to look for.

Tags
throws
NotFoundExceptionInterface

No entry was found for this identifier.

throws
ContainerExceptionInterface

Error while retrieving the entry.

Return values
mixedEntry.

has()

Returns true if the container can return an entry for the given identifier.

public has(string $id) : bool

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.

Parameters
$id : string

Identifier of the entry to look for.

Return values
bool