RoutingResolverPass.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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\Routing\DependencyInjection;
  11. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  12. use Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceTrait;
  13. use Symfony\Component\DependencyInjection\ContainerBuilder;
  14. use Symfony\Component\DependencyInjection\Reference;
  15. /**
  16. * Adds tagged routing.loader services to routing.resolver service.
  17. *
  18. * @author Fabien Potencier <fabien@symfony.com>
  19. */
  20. class RoutingResolverPass implements CompilerPassInterface
  21. {
  22. use PriorityTaggedServiceTrait;
  23. private $resolverServiceId;
  24. private $loaderTag;
  25. public function __construct(string $resolverServiceId = 'routing.resolver', string $loaderTag = 'routing.loader')
  26. {
  27. $this->resolverServiceId = $resolverServiceId;
  28. $this->loaderTag = $loaderTag;
  29. }
  30. public function process(ContainerBuilder $container)
  31. {
  32. if (false === $container->hasDefinition($this->resolverServiceId)) {
  33. return;
  34. }
  35. $definition = $container->getDefinition($this->resolverServiceId);
  36. foreach ($this->findAndSortTaggedServices($this->loaderTag, $container) as $id) {
  37. $definition->addMethodCall('addLoader', [new Reference($id)]);
  38. }
  39. }
  40. }