Automattic\WooCommerce\Internal\DependencyManagement

ExtendedContainer::add()publicWC 1.0

Register a class in the container.

Method of the class: ExtendedContainer{}

No Hooks.

Return

DefinitionInterface. The generated definition for the container.

Usage

$ExtendedContainer = new ExtendedContainer();
$ExtendedContainer->add( $class_name, $concrete, $shared ) : DefinitionInterface;
$class_name(string) (required)
Class name.
$concrete(mixed)
How to resolve the class with get: a factory callback, a concrete instance, another class name, or null to just create an instance of the class.
Default: null
$shared(true|false|null)
Whether the resolution should be performed only once and cached.
Default: null

ExtendedContainer::add() code WC 8.6.1

public function add( string $class_name, $concrete = null, bool $shared = null ) : DefinitionInterface {
	if ( ! $this->is_class_allowed( $class_name ) ) {
		throw new ContainerException( "You cannot add '$class_name', only classes in the {$this->woocommerce_namespace} namespace are allowed." );
	}

	$concrete_class = $this->get_class_from_concrete( $concrete );
	if ( isset( $concrete_class ) && ! $this->is_class_allowed( $concrete_class ) ) {
		throw new ContainerException( "You cannot add concrete '$concrete_class', only classes in the {$this->woocommerce_namespace} namespace are allowed." );
	}

	// We want to use a definition class that does not support constructor injection to avoid accidental usage.
	if ( ! $concrete instanceof DefinitionInterface ) {
		$concrete = new Definition( $class_name, $concrete );
	}

	return parent::add( $class_name, $concrete, $shared );
}