Automattic\WooCommerce\Internal\DependencyManagement

ExtendedContainer::add()publicWC 1.0

Register a class in the container.

Метод класса: ExtendedContainer{}

Хуков нет.

Возвращает

DefinitionInterface. The generated definition for the container.

Использование

$ExtendedContainer = new ExtendedContainer();
$ExtendedContainer->add( $class_name, $concrete, $shared ) : DefinitionInterface;
$class_name(строка) (обязательный)
Class name.
$concrete(разное)
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.
По умолчанию: null
$shared(true|false|null)
Whether the resolution should be performed only once and cached.
По умолчанию: null

Код ExtendedContainer::add() WC 8.7.0

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 );
}