Class ReflectionContainer
Property Summary
-
$cache protected
array -
$container protected
Cake\Container\ContainerInterface|null
Method Summary
-
__construct() public
-
call() public
-
get() public
-
getContainer() abstract public
-
getNew() public
Get a new instance, bypassing the cache.
-
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. -
reflectArguments() public
-
resolveArgumentFromAttribute() protected
Attempt to resolve a parameter's value from one of its PHP attributes.
-
resolveArguments() public
-
resolveContextualArgumentFromAttribute() protected
Attempt to resolve a parameter's value from a contextual PHP attribute.
Contextual attributes receive the parameter being resolved alongside the container, enabling resolution by parameter name/type. Attributes not implementing {@see ContextualAttributeInterface} return false here and fall through to {@see resolveArgumentFromAttribute()}.
The container is deliberately passed as an argument instead of using {@see ContainerAwareInterface}: with a standalone ReflectionContainer there is no parent container to inject, while the resolving instance itself always satisfies the PSR interface expected here.
-
setContainer() public
Method Detail
__construct() ¶ public
__construct(bool $cacheResolutions = false)
Parameters
-
bool$cacheResolutions optional
call() ¶ public
call(callable|string $callable, array $args = []): mixed
Parameters
-
callable|string$callable -
array$args optional
Returns
mixedThrows
Psr\Container\ContainerExceptionInterfacePsr\Container\NotFoundExceptionInterfaceReflectionExceptiongetContainer() ¶ abstract public
getContainer(): Cake\Container\ContainerInterface
Returns
Cake\Container\ContainerInterfacegetNew() ¶ public
getNew(string $id, array<string, mixed> $args = []): mixed
Get a new instance, bypassing the cache.
Parameters
-
string$id -
array<string, mixed>$args optional
Returns
mixedhas() ¶ 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
Returns
boolreflectArguments() ¶ public
reflectArguments(ReflectionFunctionAbstract $method, array $args = []): array
Parameters
-
ReflectionFunctionAbstract$method -
array$args optional
Returns
arrayresolveArgumentFromAttribute() ¶ protected
resolveArgumentFromAttribute(ReflectionAttribute<object> $attribute): Cake\Container\Argument\LiteralArgumentInterface|false
Attempt to resolve a parameter's value from one of its PHP attributes.
Parameters
-
ReflectionAttribute<object>$attribute The attribute to attempt to resolve.
Returns
Cake\Container\Argument\LiteralArgumentInterface|falseresolveArguments() ¶ public
resolveArguments(array<Cake\Container\Argument\ArgumentInterface> $arguments): array
Parameters
-
array<Cake\Container\Argument\ArgumentInterface>$arguments
Returns
arrayresolveContextualArgumentFromAttribute() ¶ protected
resolveContextualArgumentFromAttribute(ReflectionAttribute<object> $attribute, ReflectionParameter $parameter): Cake\Container\Argument\LiteralArgumentInterface|false
Attempt to resolve a parameter's value from a contextual PHP attribute.
Contextual attributes receive the parameter being resolved alongside the container, enabling resolution by parameter name/type. Attributes not implementing {@see ContextualAttributeInterface} return false here and fall through to {@see resolveArgumentFromAttribute()}.
The container is deliberately passed as an argument instead of using {@see ContainerAwareInterface}: with a standalone ReflectionContainer there is no parent container to inject, while the resolving instance itself always satisfies the PSR interface expected here.
Parameters
-
ReflectionAttribute<object>$attribute The attribute to attempt to resolve.
-
ReflectionParameter$parameter The parameter being resolved.
Returns
Cake\Container\Argument\LiteralArgumentInterface|falsesetContainer() ¶ public
setContainer(Cake\Container\ContainerInterface $container): ContainerAwareInterface
Parameters
-
Cake\Container\ContainerInterface$container
Returns
ContainerAwareInterface