No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PropertyInfoPass.php 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. if (0 < \func_num_args()) {
  32. trigger_deprecation('symfony/property-info', '5.3', 'Configuring "%s" is deprecated.', __CLASS__);
  33. }
  34. $this->propertyInfoService = $propertyInfoService;
  35. $this->listExtractorTag = $listExtractorTag;
  36. $this->typeExtractorTag = $typeExtractorTag;
  37. $this->descriptionExtractorTag = $descriptionExtractorTag;
  38. $this->accessExtractorTag = $accessExtractorTag;
  39. $this->initializableExtractorTag = $initializableExtractorTag;
  40. }
  41. /**
  42. * {@inheritdoc}
  43. */
  44. public function process(ContainerBuilder $container)
  45. {
  46. if (!$container->hasDefinition($this->propertyInfoService)) {
  47. return;
  48. }
  49. $definition = $container->getDefinition($this->propertyInfoService);
  50. $listExtractors = $this->findAndSortTaggedServices($this->listExtractorTag, $container);
  51. $definition->replaceArgument(0, new IteratorArgument($listExtractors));
  52. $typeExtractors = $this->findAndSortTaggedServices($this->typeExtractorTag, $container);
  53. $definition->replaceArgument(1, new IteratorArgument($typeExtractors));
  54. $descriptionExtractors = $this->findAndSortTaggedServices($this->descriptionExtractorTag, $container);
  55. $definition->replaceArgument(2, new IteratorArgument($descriptionExtractors));
  56. $accessExtractors = $this->findAndSortTaggedServices($this->accessExtractorTag, $container);
  57. $definition->replaceArgument(3, new IteratorArgument($accessExtractors));
  58. $initializableExtractors = $this->findAndSortTaggedServices($this->initializableExtractorTag, $container);
  59. $definition->setArgument(4, new IteratorArgument($initializableExtractors));
  60. }
  61. }