PropertyInfoPass.php
76 lines
| 1 | <?php |
| 2 | |
| 3 | /* |
| 4 | * This file is part of the Symfony package. |
| 5 | * |
| 6 | * (c) Fabien Potencier <fabien@symfony.com> |
| 7 | * |
| 8 | * For the full copyright and license information, please view the LICENSE |
| 9 | * file that was distributed with this source code. |
| 10 | */ |
| 11 | |
| 12 | namespace Symfony\Component\PropertyInfo\DependencyInjection; |
| 13 | |
| 14 | use Symfony\Component\DependencyInjection\Argument\IteratorArgument; |
| 15 | use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
| 16 | use Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceTrait; |
| 17 | use Symfony\Component\DependencyInjection\ContainerBuilder; |
| 18 | |
| 19 | /** |
| 20 | * Adds extractors to the property_info service. |
| 21 | * |
| 22 | * @author Kévin Dunglas <dunglas@gmail.com> |
| 23 | */ |
| 24 | class PropertyInfoPass implements CompilerPassInterface |
| 25 | { |
| 26 | use PriorityTaggedServiceTrait; |
| 27 | |
| 28 | private $propertyInfoService; |
| 29 | private $listExtractorTag; |
| 30 | private $typeExtractorTag; |
| 31 | private $descriptionExtractorTag; |
| 32 | private $accessExtractorTag; |
| 33 | private $initializableExtractorTag; |
| 34 | |
| 35 | public function __construct(string $propertyInfoService = 'property_info', string $listExtractorTag = 'property_info.list_extractor', string $typeExtractorTag = 'property_info.type_extractor', string $descriptionExtractorTag = 'property_info.description_extractor', string $accessExtractorTag = 'property_info.access_extractor', string $initializableExtractorTag = 'property_info.initializable_extractor') |
| 36 | { |
| 37 | if (0 < \func_num_args()) { |
| 38 | trigger_deprecation('symfony/property-info', '5.3', 'Configuring "%s" is deprecated.', __CLASS__); |
| 39 | } |
| 40 | |
| 41 | $this->propertyInfoService = $propertyInfoService; |
| 42 | $this->listExtractorTag = $listExtractorTag; |
| 43 | $this->typeExtractorTag = $typeExtractorTag; |
| 44 | $this->descriptionExtractorTag = $descriptionExtractorTag; |
| 45 | $this->accessExtractorTag = $accessExtractorTag; |
| 46 | $this->initializableExtractorTag = $initializableExtractorTag; |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * {@inheritdoc} |
| 51 | */ |
| 52 | public function process(ContainerBuilder $container) |
| 53 | { |
| 54 | if (!$container->hasDefinition($this->propertyInfoService)) { |
| 55 | return; |
| 56 | } |
| 57 | |
| 58 | $definition = $container->getDefinition($this->propertyInfoService); |
| 59 | |
| 60 | $listExtractors = $this->findAndSortTaggedServices($this->listExtractorTag, $container); |
| 61 | $definition->replaceArgument(0, new IteratorArgument($listExtractors)); |
| 62 | |
| 63 | $typeExtractors = $this->findAndSortTaggedServices($this->typeExtractorTag, $container); |
| 64 | $definition->replaceArgument(1, new IteratorArgument($typeExtractors)); |
| 65 | |
| 66 | $descriptionExtractors = $this->findAndSortTaggedServices($this->descriptionExtractorTag, $container); |
| 67 | $definition->replaceArgument(2, new IteratorArgument($descriptionExtractors)); |
| 68 | |
| 69 | $accessExtractors = $this->findAndSortTaggedServices($this->accessExtractorTag, $container); |
| 70 | $definition->replaceArgument(3, new IteratorArgument($accessExtractors)); |
| 71 | |
| 72 | $initializableExtractors = $this->findAndSortTaggedServices($this->initializableExtractorTag, $container); |
| 73 | $definition->setArgument(4, new IteratorArgument($initializableExtractors)); |
| 74 | } |
| 75 | } |
| 76 |