Interface ContainerInterface
Interface for the Dependency Injection Container in CakePHP applications
This interface extends the PSR-11 container interface and adds methods to add services and service providers to the container.
The methods defined in this interface use the conventions provided by league/container as that is the library that CakePHP uses.
Method Summary
-
add() public
Add an item to the container.
-
addServiceProvider() public
Add a service provider to the 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.
Method Detail
add() ¶ public
add(string $id, mixed $concrete = null, bool $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.-
bool$shared optional Set to true to make a service shared.
Returns
League\Container\Definition\DefinitionInterfaceaddServiceProvider() ¶ public
addServiceProvider(League\Container\ServiceProvider\ServiceProviderInterface $provider): $this
Add a service provider to the container
Parameters
-
League\Container\ServiceProvider\ServiceProviderInterface$provider The service provider to add.
Returns
$thisextend() ¶ 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
bool