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.

53 lines
1.6 KiB

4 years ago
  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. if (0 < \func_num_args()) {
  28. trigger_deprecation('symfony/routing', '5.3', 'Configuring "%s" is deprecated.', __CLASS__);
  29. }
  30. $this->resolverServiceId = $resolverServiceId;
  31. $this->loaderTag = $loaderTag;
  32. }
  33. public function process(ContainerBuilder $container)
  34. {
  35. if (false === $container->hasDefinition($this->resolverServiceId)) {
  36. return;
  37. }
  38. $definition = $container->getDefinition($this->resolverServiceId);
  39. foreach ($this->findAndSortTaggedServices($this->loaderTag, $container) as $id) {
  40. $definition->addMethodCall('addLoader', [new Reference($id)]);
  41. }
  42. }
  43. }