RoutingResolverPass.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\Routing\DependencyInjection;
  11. use Symfony\Component\DependencyInjection\Reference;
  12. use Symfony\Component\DependencyInjection\ContainerBuilder;
  13. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  14. use Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceTrait;
  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($resolverServiceId = 'routing.resolver', $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', array(new Reference($id)));
  38. }
  39. }
  40. }