Drupal investigation

RegisterRoutersPass.php 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /*
  3. * This file is part of the Symfony CMF package.
  4. *
  5. * (c) 2011-2015 Symfony CMF
  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\Cmf\Component\Routing\DependencyInjection\Compiler;
  11. use Symfony\Component\DependencyInjection\ContainerBuilder;
  12. use Symfony\Component\DependencyInjection\Reference;
  13. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  14. /**
  15. * Compiler pass to register routers to the ChainRouter.
  16. *
  17. * @author Wouter J <waldio.webdesign@gmail.com>
  18. * @author Henrik Bjornskov <henrik@bjrnskov.dk>
  19. * @author Magnus Nordlander <magnus@e-butik.se>
  20. */
  21. class RegisterRoutersPass implements CompilerPassInterface
  22. {
  23. /**
  24. * @var string
  25. */
  26. protected $chainRouterService;
  27. protected $routerTag;
  28. public function __construct($chainRouterService = 'cmf_routing.router', $routerTag = 'router')
  29. {
  30. $this->chainRouterService = $chainRouterService;
  31. $this->routerTag = $routerTag;
  32. }
  33. public function process(ContainerBuilder $container)
  34. {
  35. if (!$container->hasDefinition($this->chainRouterService)) {
  36. return;
  37. }
  38. $definition = $container->getDefinition($this->chainRouterService);
  39. foreach ($container->findTaggedServiceIds($this->routerTag) as $id => $attributes) {
  40. $priority = isset($attributes[0]['priority']) ? $attributes[0]['priority'] : 0;
  41. $definition->addMethodCall('add', array(new Reference($id), $priority));
  42. }
  43. }
  44. }