PropertyInfoPass.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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\PropertyInfo\DependencyInjection;
  11. use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
  12. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  13. use Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceTrait;
  14. use Symfony\Component\DependencyInjection\ContainerBuilder;
  15. /**
  16. * Adds extractors to the property_info service.
  17. *
  18. * @author Kévin Dunglas <dunglas@gmail.com>
  19. */
  20. class PropertyInfoPass implements CompilerPassInterface
  21. {
  22. use PriorityTaggedServiceTrait;
  23. private $propertyInfoService;
  24. private $listExtractorTag;
  25. private $typeExtractorTag;
  26. private $descriptionExtractorTag;
  27. private $accessExtractorTag;
  28. private $initializableExtractorTag;
  29. 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')
  30. {
  31. $this->propertyInfoService = $propertyInfoService;
  32. $this->listExtractorTag = $listExtractorTag;
  33. $this->typeExtractorTag = $typeExtractorTag;
  34. $this->descriptionExtractorTag = $descriptionExtractorTag;
  35. $this->accessExtractorTag = $accessExtractorTag;
  36. $this->initializableExtractorTag = $initializableExtractorTag;
  37. }
  38. /**
  39. * {@inheritdoc}
  40. */
  41. public function process(ContainerBuilder $container)
  42. {
  43. if (!$container->hasDefinition($this->propertyInfoService)) {
  44. return;
  45. }
  46. $definition = $container->getDefinition($this->propertyInfoService);
  47. $listExtractors = $this->findAndSortTaggedServices($this->listExtractorTag, $container);
  48. $definition->replaceArgument(0, new IteratorArgument($listExtractors));
  49. $typeExtractors = $this->findAndSortTaggedServices($this->typeExtractorTag, $container);
  50. $definition->replaceArgument(1, new IteratorArgument($typeExtractors));
  51. $descriptionExtractors = $this->findAndSortTaggedServices($this->descriptionExtractorTag, $container);
  52. $definition->replaceArgument(2, new IteratorArgument($descriptionExtractors));
  53. $accessExtractors = $this->findAndSortTaggedServices($this->accessExtractorTag, $container);
  54. $definition->replaceArgument(3, new IteratorArgument($accessExtractors));
  55. $initializableExtractors = $this->findAndSortTaggedServices($this->initializableExtractorTag, $container);
  56. $definition->setArgument(4, new IteratorArgument($initializableExtractors));
  57. }
  58. }