1728a19b816e88102e0a7989bb74663dffb07650
[yaffs-website] / vendor / symfony-cmf / routing / DependencyInjection / Compiler / RegisterRoutersPass.php
1 <?php
2
3 /*
4  * This file is part of the Symfony CMF package.
5  *
6  * (c) 2011-2015 Symfony CMF
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Cmf\Component\Routing\DependencyInjection\Compiler;
13
14 use Symfony\Component\DependencyInjection\ContainerBuilder;
15 use Symfony\Component\DependencyInjection\Reference;
16 use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
17
18 /**
19  * Compiler pass to register routers to the ChainRouter.
20  *
21  * @author Wouter J <waldio.webdesign@gmail.com>
22  * @author Henrik Bjornskov <henrik@bjrnskov.dk>
23  * @author Magnus Nordlander <magnus@e-butik.se>
24  */
25 class RegisterRoutersPass implements CompilerPassInterface
26 {
27     /**
28      * @var string
29      */
30     protected $chainRouterService;
31
32     protected $routerTag;
33
34     public function __construct($chainRouterService = 'cmf_routing.router', $routerTag = 'router')
35     {
36         $this->chainRouterService = $chainRouterService;
37         $this->routerTag = $routerTag;
38     }
39
40     public function process(ContainerBuilder $container)
41     {
42         if (!$container->hasDefinition($this->chainRouterService)) {
43             return;
44         }
45
46         $definition = $container->getDefinition($this->chainRouterService);
47
48         foreach ($container->findTaggedServiceIds($this->routerTag) as $id => $attributes) {
49             $priority = isset($attributes[0]['priority']) ? $attributes[0]['priority'] : 0;
50
51             $definition->addMethodCall('add', array(new Reference($id), $priority));
52         }
53     }
54 }