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 * This compiler pass adds additional route enhancers
20 * to the dynamic router.
22 * @author Daniel Leech <dan.t.leech@gmail.com>
23 * @author Nathaniel Catchpole (catch)
25 class RegisterRouteEnhancersPass implements CompilerPassInterface
30 protected $dynamicRouterService;
32 protected $enhancerTag;
34 public function __construct($dynamicRouterService = 'cmf_routing.dynamic_router', $enhancerTag = 'dynamic_router_route_enhancer')
36 $this->dynamicRouterService = $dynamicRouterService;
37 $this->enhancerTag = $enhancerTag;
40 public function process(ContainerBuilder $container)
42 if (!$container->hasDefinition($this->dynamicRouterService)) {
46 $router = $container->getDefinition($this->dynamicRouterService);
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));