Helper function diTaggedAs()
The diTaggedAs() helper function injects a collection of items from the container that are marked with a specific tag.
Function signature:
use Kaspi\DiContainer\Interfaces\DiDefinition\DiDefinitionNoArgumentsInterface;
\Kaspi\DiContainer\diTaggedAs(
string $tag,
bool $isLazy = true,
?string $priorityDefaultMethod = null,
bool $useKeys = true,
?string $key = null,
?string $keyDefaultMethod = null,
array $containerIdExclude = [],
bool $selfExclude = true
): DiDefinitionNoArgumentsInterfaceParameters:
$name– the tag name or the FQCN [1] of a PHP interface.$isLazy– enables a "lazy collection."$priorityDefaultMethod– retrieves the priority from a default method within the PHP class.$useKeys– uses string identifiers for 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.
The helper function has no additional methods.
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.
TIP
See the documentation section "Defining a tag in configuration files."
For more information on how collection item priorities and collection item identifiers are specified, please refer to the documentation section "Working with tags in the container."
Fully Qualified Class Name – the full name of a class or interface, including its namespace. ↩︎