Class Container
Dependency Injection container
Based on the container out of League\Container
Property Summary
-
$defaultToShared protected
boolean -
$definitions protected
DefinitionAggregateInterface -
$delegates protected
ContainerInterface[] -
$inflectors protected
InflectorAggregateInterface -
$providers protected
ServiceProviderAggregateInterface
Method Summary
-
__construct() public
Construct.
-
add() public
Add an item to the container.
-
addServiceProvider() public
Add a service provider to the container
-
defaultToShared() public
Whether the container should default to defining shared definitions.
-
delegate() public
Delegate a backup container to be checked for services if it cannot be resolved via this container.
-
extend() public
Modify an existing definition
-
get() public
Finds an entry of the container by its identifier and returns it.
-
has() public
Returns true if the container can return an entry for the given identifier. Returns false otherwise.
-
inflector() public
Allows for manipulation of specific types on resolution.
-
share() public
Proxy to add with shared as true.
Method Detail
__construct() ¶ public
__construct(DefinitionAggregateInterface|null $definitions = null, ServiceProviderAggregateInterface|null $providers = null, InflectorAggregateInterface|null $inflectors = null)
Construct.
Parameters
-
DefinitionAggregateInterface|null$definitions optional -
ServiceProviderAggregateInterface|null$providers optional -
InflectorAggregateInterface|null$inflectors optional
add() ¶ public
add(string $id, mixed $concrete = null, boolean $shared = false): League\Container\Definition\DefinitionInterface
Add an item to the container.
Parameters
-
string$id The class name or name of the service being registered.
-
mixed$concrete optional Either the classname an interface or name resolves to. Can also be a constructed object, Closure, or null. When null, the
$idparameter will be used as the concrete class name.-
boolean$shared optional Set to true to make a service shared.
Returns
League\Container\Definition\DefinitionInterfaceaddServiceProvider() ¶ public
addServiceProvider(ServiceProviderInterface|string $provider): $this
Add a service provider to the container
Parameters
-
ServiceProviderInterface|string$provider The service provider to add.
Returns
$thisdefaultToShared() ¶ public
defaultToShared(boolean $shared = true): self
Whether the container should default to defining shared definitions.
Parameters
-
boolean$shared optional
Returns
selfdelegate() ¶ public
delegate(ContainerInterface $container): self
Delegate a backup container to be checked for services if it cannot be resolved via this container.
Parameters
-
ContainerInterface$container
Returns
selfextend() ¶ public
extend(string $id): League\Container\Definition\DefinitionInterface
Modify an existing definition
Parameters
-
string$id The class name or name of the service being modified.
Returns
League\Container\Definition\DefinitionInterfaceget() ¶ public
get(string $id): mixed
Finds an entry of the container by its identifier and returns it.
Parameters
-
string$id Identifier of the entry to look for.
Returns
mixedEntry.
Throws
NotFoundExceptionInterfaceNo entry was found for **this** identifier.
ContainerExceptionInterfaceError while retrieving the entry.
has() ¶ public
has(string $id): bool
Returns true if the container can return an entry for the given identifier. 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
-
string$id Identifier of the entry to look for.
Returns
boolinflector() ¶ public
inflector(string $type, callable|null $callback = null): InflectorInterface
Allows for manipulation of specific types on resolution.
Parameters
-
string$type -
callable|null$callback optional
Returns
InflectorInterfaceshare() ¶ public
share(string $id, mixed $concrete = null): DefinitionInterface
Proxy to add with shared as true.
Parameters
-
string$id -
mixed$concrete optional
Returns
DefinitionInterface