Automattic\WooCommerce\Blocks\Registry
Container::register()
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.
Method of the class: Container{}
No Hooks.
Return
null
. Nothing (null).
Usage
$Container = new Container(); $Container->register( $id, $value );
- $id(string) (required)
- A unique string identifier for the provided value. Typically it's the fully qualified name for the dependency.
- $value(mixed) (required)
- The value for the dependency. Typically, this is a closure that will create the class instance needed.
Container::register() Container::register code WC 9.7.1
public function register( $id, $value ) { if ( empty( $this->registry[ $id ] ) ) { if ( ! $value instanceof FactoryType ) { $value = new SharedType( $value ); } $this->registry[ $id ] = $value; } }