TaggedAs attribute
The \Kaspi\DiContainer\Attributes\TaggedAs attribute injects a collection of items from the container that are marked with a tag of the same name.
Attribute configuration:
\Attribute::TARGET_PARAMETER\Attribute::IS_REPEATABLE
Attribute signature:
php
\Kaspi\DiContainer\Attributes\TaggedAs::__construct(
string $name,
bool $isLazy = true,
?string $priorityDefaultMethod = null,
bool $useKeys = true,
?string $key = null,
?string $keyDefaultMethod = null,
array $containerIdExclude = [],
bool $selfExclude = true
)Parameters:
$name– the tag name or the FQCN [1] of an interface.$isLazy– enables a "lazy collection."$priorityDefaultMethod– retrieves the priority from a default method within the PHP class.$useKeys– uses string identifiers for the collection elements.$key– retrieves the identifier for a collection element based on a metadata name from the tag.$keyDefaultMethod– retrieves the identifier for a collection element from a default method within the PHP class.$containerIdExclude– excludes elements from the collection based on their container ID.$selfExclude– excludes the calling PHP class from the collection.
IMPORTANT
PHP classes that have not been explicitly registered in the container will be ignored during tag-based lookups; therefore, you must ensure that these classes are added to the container using one of the following methods:
- importing PHP classes — via the
DiContainerBuilder::import()method. - using configuration files — via the
DiContainerBuilder::load()method.
Fully Qualified Class Name – the full name of a class or interface, including its namespace. ↩︎