Version 1
[yaffs-website] / vendor / symfony-cmf / routing / DependencyInjection / Compiler / RegisterRouteEnhancersPass.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  * This compiler pass adds additional route enhancers
20  * to the dynamic router.
21  *
22  * @author Daniel Leech <dan.t.leech@gmail.com>
23  * @author Nathaniel Catchpole (catch)
24  */
25 class RegisterRouteEnhancersPass implements CompilerPassInterface
26 {
27     /**
28      * @var string
29      */
30     protected $dynamicRouterService;
31
32     protected $enhancerTag;
33
34     public function __construct($dynamicRouterService = 'cmf_routing.dynamic_router', $enhancerTag = 'dynamic_router_route_enhancer')
35     {
36         $this->dynamicRouterService = $dynamicRouterService;
37         $this->enhancerTag = $enhancerTag;
38     }
39
40     public function process(ContainerBuilder $container)
41     {
42         if (!$container->hasDefinition($this->dynamicRouterService)) {
43             return;
44         }
45
46         $router = $container->getDefinition($this->dynamicRouterService);
47
48         foreach ($container->findTaggedServiceIds($this->enhancerTag) as $id => $attributes) {
49             $priority = isset($attributes[0]['priority']) ? $attributes[0]['priority'] : 0;
50             $router->addMethodCall('addRouteEnhancer', array(new Reference($id), $priority));
51         }
52     }
53 }