Automattic\WooCommerce\Blocks\Registry

Container::register()publicWC 1.0

Interface for registering a new dependency with the container.

By default, the $value will be added as a shared dependency. This means that it will be a single instance shared among any other classes having that dependency.

If you want a new instance every time it's required, then wrap the value in a call to the factory method (@see Container::factory for example)

Note: Currently if the provided id already is registered in the container, the provided value is ignored.

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

Хуков нет.

Возвращает

null. Ничего (null).

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

$Container = new Container();
$Container->register( $id, $value );
$id(строка) (обязательный)
A unique string identifier for the provided value. Typically it's the fully qualified name for the dependency.
$value(разное) (обязательный)
The value for the dependency. Typically, this is a closure that will create the class instance needed.

Код Container::register() WC 8.7.0

public function register( $id, $value ) {
	if ( empty( $this->registry[ $id ] ) ) {
		if ( ! $value instanceof FactoryType ) {
			$value = new SharedType( $value );
		}
		$this->registry[ $id ] = $value;
	}
}