RoutingResolverPass.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. /**
  15. * Adds tagged routing.loader services to routing.resolver service.
  16. *
  17. * @author Fabien Potencier <fabien@symfony.com>
  18. */
  19. class RoutingResolverPass implements CompilerPassInterface
  20. {
  21. private $resolverServiceId;
  22. private $loaderTag;
  23. public function __construct($resolverServiceId = 'routing.resolver', $loaderTag = 'routing.loader')
  24. {
  25. $this->resolverServiceId = $resolverServiceId;
  26. $this->loaderTag = $loaderTag;
  27. }
  28. public function process(ContainerBuilder $container)
  29. {
  30. if (false === $container->hasDefinition($this->resolverServiceId)) {
  31. return;
  32. }
  33. $definition = $container->getDefinition($this->resolverServiceId);
  34. foreach ($container->findTaggedServiceIds($this->loaderTag, true) as $id => $attributes) {
  35. $definition->addMethodCall('addLoader', array(new Reference($id)));
  36. }
  37. }
  38. }