* @author Nathaniel Catchpole (catch) */ class RegisterRouteEnhancersPass implements CompilerPassInterface { /** * @var string Service name of the dynamic router */ private $dynamicRouterService; /** * @var string Name of the tag */ private $enhancerTag; public function __construct($dynamicRouterService = 'cmf_routing.dynamic_router', $enhancerTag = 'dynamic_router_route_enhancer') { $this->dynamicRouterService = $dynamicRouterService; $this->enhancerTag = $enhancerTag; } /** * {@inheritdoc} */ public function process(ContainerBuilder $container) { if (!$container->hasDefinition($this->dynamicRouterService)) { return; } $router = $container->getDefinition($this->dynamicRouterService); foreach ($container->findTaggedServiceIds($this->enhancerTag) as $id => $attributes) { $priority = isset($attributes[0]['priority']) ? $attributes[0]['priority'] : 0; $router->addMethodCall('addRouteEnhancer', [new Reference($id), $priority]); } } }