Class Container
Dependency Injection container
Based on the container out of League\Container
Namespace: Cake\Core
Property Summary
-
$delegates protected
ContainerInterface[] -
$eventDispatcher protected
?EventDispatcher
Method Summary
-
__construct() public
-
add() public
-
addListener() public
-
addServiceProvider() public
-
addShared() public
-
afterResolve() public
-
defaultToOverwrite() public
-
defaultToShared() public
-
delegate() public
-
dispatchEvent() protected
-
extend() public
-
get() public
Finds an entry of the container by its identifier and returns it.
-
getDefinitionTags() protected
-
getDelegate() public
-
getEventDispatcher() public
-
getNew() public
-
has() public
Returns true if the container can return an entry for the given identifier. Returns false otherwise.
-
inflector() public deprecated
-
listen() public
-
resolve() protected
-
setEventDispatcher() public
Method Detail
__construct() ¶ public
__construct(DefinitionAggregateInterface $definitions = new DefinitionAggregate(), ServiceProviderAggregateInterface $providers = new ServiceProviderAggregate(), InflectorAggregateInterface $inflectors = new InflectorAggregate(), bool $defaultToShared = false, bool $defaultToOverwrite = false)
Parameters
-
DefinitionAggregateInterface$definitions optional -
ServiceProviderAggregateInterface$providers optional -
InflectorAggregateInterface$inflectors optional -
bool$defaultToShared optional -
bool$defaultToOverwrite optional
add() ¶ public
add(string $id, mixed $concrete = null, bool $overwrite = false): DefinitionInterface
Parameters
-
string$id -
mixed$concrete optional -
bool$overwrite optional
Returns
DefinitionInterfaceaddListener() ¶ public
addListener(string $eventType, callable $listener): void
Parameters
-
string$eventType -
callable$listener
Returns
voidaddServiceProvider() ¶ public
addServiceProvider(ServiceProviderInterface $provider): self
Parameters
-
ServiceProviderInterface$provider
Returns
selfaddShared() ¶ public
addShared(string $id, mixed $concrete = null, bool $overwrite = false): DefinitionInterface
Parameters
-
string$id -
mixed$concrete optional -
bool$overwrite optional
Returns
DefinitionInterfaceafterResolve() ¶ public
afterResolve(string $type, callable $callback): EventFilter
Parameters
-
string$type -
callable$callback
Returns
EventFilterdefaultToOverwrite() ¶ public
defaultToOverwrite(bool $overwrite = true): ContainerInterface
Parameters
-
bool$overwrite optional
Returns
ContainerInterfacedefaultToShared() ¶ public
defaultToShared(bool $shared = true): ContainerInterface
Parameters
-
bool$shared optional
Returns
ContainerInterfacedelegate() ¶ public
delegate(Psr\Container\ContainerInterface $container): Psr\Container\ContainerInterface
Parameters
-
Psr\Container\ContainerInterface$container The container instance to use as delegation
Returns
Psr\Container\ContainerInterfacedispatchEvent() ¶ protected
dispatchEvent(ContainerEvent $event): ContainerEvent
Parameters
-
ContainerEvent$event
Returns
ContainerEventextend() ¶ public
extend(string $id): DefinitionInterface
Parameters
-
string$id
Returns
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.
getDefinitionTags() ¶ protected
getDefinitionTags(DefinitionInterface $definition): array
Parameters
-
DefinitionInterface$definition
Returns
arraygetDelegate() ¶ public
getDelegate(string $class): ContainerInterface
Parameters
-
string$class
Returns
ContainerInterfacehas() ¶ 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 $callback = null): InflectorInterface
Parameters
-
string$type -
?callable$callback optional
Returns
InflectorInterfacelisten() ¶ public
listen(string $eventType, callable $listener): EventFilter
Parameters
-
string$eventType -
callable$listener
Returns
EventFilterresolve() ¶ protected
resolve(string $id, bool $new = false): mixed
Parameters
-
string$id -
bool$new optional
Returns
mixedThrows
ContainerExceptionInterfaceNotFoundExceptionInterfacesetEventDispatcher() ¶ public
setEventDispatcher(?EventDispatcher $eventDispatcher): void
Parameters
-
?EventDispatcher$eventDispatcher
Returns
void