4 * This file is part of the Symfony CMF package.
6 * (c) 2011-2015 Symfony CMF
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Cmf\Component\Routing\DependencyInjection\Compiler;
14 use Symfony\Component\DependencyInjection\ContainerBuilder;
15 use Symfony\Component\DependencyInjection\Reference;
16 use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
19 * Compiler pass to register routers to the ChainRouter.
21 * @author Wouter J <waldio.webdesign@gmail.com>
22 * @author Henrik Bjornskov <henrik@bjrnskov.dk>
23 * @author Magnus Nordlander <magnus@e-butik.se>
25 class RegisterRoutersPass implements CompilerPassInterface
30 protected $chainRouterService;
34 public function __construct($chainRouterService = 'cmf_routing.router', $routerTag = 'router')
36 $this->chainRouterService = $chainRouterService;
37 $this->routerTag = $routerTag;
40 public function process(ContainerBuilder $container)
42 if (!$container->hasDefinition($this->chainRouterService)) {
46 $definition = $container->getDefinition($this->chainRouterService);
48 foreach ($container->findTaggedServiceIds($this->routerTag) as $id => $attributes) {
49 $priority = isset($attributes[0]['priority']) ? $attributes[0]['priority'] : 0;
51 $definition->addMethodCall('add', array(new Reference($id), $priority));