PropertyInfoConstructorPass.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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.constructor_extractor service.
  17. *
  18. * @author Dmitrii Poddubnyi <dpoddubny@gmail.com>
  19. */
  20. final class PropertyInfoConstructorPass implements CompilerPassInterface
  21. {
  22. use PriorityTaggedServiceTrait;
  23. private $service;
  24. private $tag;
  25. public function __construct(string $service = 'property_info.constructor_extractor', string $tag = 'property_info.constructor_extractor')
  26. {
  27. $this->service = $service;
  28. $this->tag = $tag;
  29. }
  30. /**
  31. * {@inheritdoc}
  32. */
  33. public function process(ContainerBuilder $container)
  34. {
  35. if (!$container->hasDefinition($this->service)) {
  36. return;
  37. }
  38. $definition = $container->getDefinition($this->service);
  39. $listExtractors = $this->findAndSortTaggedServices($this->tag, $container);
  40. $definition->replaceArgument(0, new IteratorArgument($listExtractors));
  41. }
  42. }