Interface ContainerInterface
Method Summary
-
add() public
-
addDefinitions() public
Add multiple definitions at once.
Supports multiple formats:
[Foo::class]- class name as value, registers as itself['alias' => Foo::class]- alias as key, class as value[Foo::class => [Bar::class]]- class with constructor arguments
-
addServiceProvider() public
-
addShared() public
-
delegate() public
-
extend() public
-
get() public
Finds an entry of the container by its identifier and returns it.
-
getNew() public
-
has() public
Returns true if the container can return an entry for the given identifier. Returns false otherwise.
has($id)returning true does not mean thatget($id)will not throw an exception. It does however mean thatget($id)will not throw aNotFoundExceptionInterface. -
hasDefinition() public
Check if the container has a registered definition for the given id.
Unlike
has(), this only checks explicit definitions, not service providers or delegate containers. -
inflector() public
Method Detail
add() ¶ public
add(string $id, mixed $concrete = null): Cake\Container\Definition\DefinitionInterface
Parameters
-
string$id -
mixed$concrete optional
Returns
Cake\Container\Definition\DefinitionInterfaceaddDefinitions() ¶ public
addDefinitions(array<int|string, array<class-string>|class-string> $definitions): self
Add multiple definitions at once.
Supports multiple formats:
[Foo::class]- class name as value, registers as itself['alias' => Foo::class]- alias as key, class as value[Foo::class => [Bar::class]]- class with constructor arguments
Parameters
-
array<int|string, array<class-string>|class-string>$definitions
Returns
selfaddServiceProvider() ¶ public
addServiceProvider(Cake\Container\ServiceProvider\ServiceProviderInterface $provider): self
Parameters
-
Cake\Container\ServiceProvider\ServiceProviderInterface$provider
Returns
selfaddShared() ¶ public
addShared(string $id, mixed $concrete = null): Cake\Container\Definition\DefinitionInterface
Parameters
-
string$id -
mixed$concrete optional
Returns
Cake\Container\Definition\DefinitionInterfacedelegate() ¶ public
delegate(Psr\Container\ContainerInterface $container): self
Parameters
-
Psr\Container\ContainerInterface$container The container instance to use as delegation
Returns
selfextend() ¶ public
extend(string $id): Cake\Container\Definition\DefinitionInterface
Parameters
-
string$id
Returns
Cake\Container\Definition\DefinitionInterfaceget() ¶ public
get(string $id): $id is class-string<T> ? T : mixed
Finds an entry of the container by its identifier and returns it.
Templates
T
of object Parameters
-
string$id Identifier of the entry to look for.
Returns
$id is class-string<T> ? T : mixedThrows
Psr\Container\NotFoundExceptionInterfaceNo entry was found for **this** identifier.
Psr\Container\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
boolhasDefinition() ¶ public
hasDefinition(string $id): bool
Check if the container has a registered definition for the given id.
Unlike has(), this only checks explicit definitions, not service providers
or delegate containers.
Parameters
-
string$id
Returns
boolinflector() ¶ public
inflector(string $type, callable|null $callback = null): Cake\Container\Inflector\InflectorInterface
Parameters
-
string$type -
callable|null$callback optional
Returns
Cake\Container\Inflector\InflectorInterface