vendor/symfony/dependency-injection/Argument/TaggedIteratorArgument.php line 36

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Component\DependencyInjection\Argument;
  11. /**
  12.  * Represents a collection of services found by tag name to lazily iterate over.
  13.  *
  14.  * @author Roland Franssen <franssen.roland@gmail.com>
  15.  */
  16. class TaggedIteratorArgument extends IteratorArgument
  17. {
  18.     private string $tag;
  19.     private mixed $indexAttribute;
  20.     private ?string $defaultIndexMethod;
  21.     private ?string $defaultPriorityMethod;
  22.     private bool $needsIndexes;
  23.     private array $exclude;
  24.     /**
  25.      * @param string      $tag                   The name of the tag identifying the target services
  26.      * @param string|null $indexAttribute        The name of the attribute that defines the key referencing each service in the tagged collection
  27.      * @param string|null $defaultIndexMethod    The static method that should be called to get each service's key when their tag doesn't define the previous attribute
  28.      * @param bool        $needsIndexes          Whether indexes are required and should be generated when computing the map
  29.      * @param string|null $defaultPriorityMethod The static method that should be called to get each service's priority when their tag doesn't define the "priority" attribute
  30.      * @param array       $exclude               Services to exclude from the iterator
  31.      */
  32.     public function __construct(string $tagstring $indexAttribute nullstring $defaultIndexMethod nullbool $needsIndexes falsestring $defaultPriorityMethod null, array $exclude = [])
  33.     {
  34.         parent::__construct([]);
  35.         if (null === $indexAttribute && $needsIndexes) {
  36.             $indexAttribute preg_match('/[^.]++$/'$tag$m) ? $m[0] : $tag;
  37.         }
  38.         $this->tag $tag;
  39.         $this->indexAttribute $indexAttribute;
  40.         $this->defaultIndexMethod $defaultIndexMethod ?: ($indexAttribute 'getDefault'.str_replace(' '''ucwords(preg_replace('/[^a-zA-Z0-9\x7f-\xff]++/'' '$indexAttribute))).'Name' null);
  41.         $this->needsIndexes $needsIndexes;
  42.         $this->defaultPriorityMethod $defaultPriorityMethod ?: ($indexAttribute 'getDefault'.str_replace(' '''ucwords(preg_replace('/[^a-zA-Z0-9\x7f-\xff]++/'' '$indexAttribute))).'Priority' null);
  43.         $this->exclude $exclude;
  44.     }
  45.     public function getTag()
  46.     {
  47.         return $this->tag;
  48.     }
  49.     public function getIndexAttribute(): ?string
  50.     {
  51.         return $this->indexAttribute;
  52.     }
  53.     public function getDefaultIndexMethod(): ?string
  54.     {
  55.         return $this->defaultIndexMethod;
  56.     }
  57.     public function needsIndexes(): bool
  58.     {
  59.         return $this->needsIndexes;
  60.     }
  61.     public function getDefaultPriorityMethod(): ?string
  62.     {
  63.         return $this->defaultPriorityMethod;
  64.     }
  65.     public function getExclude(): array
  66.     {
  67.         return $this->exclude;
  68.     }
  69. }