@@ -22,13 +22,69 @@ Writing your own Route Enhancers
2222
2323You can add your own :ref: `RouteEnhancerInterface <bundles-routing-dynamic_router-enhancer >`
2424implementations if you have a case not handled by the
25- :ref: `provided enhancers <component-routing-enhancers >`. Simply define services
26- for your enhancers and tag them with ``dynamic_router_route_enhancer `` to have
27- them added to the routing. You can specify an optional ``priority `` parameter
28- on the tag to control the order in which enhancers are executed. The higher the
29- priority, the earlier the enhancer is executed.
25+ :ref: `provided enhancers <component-routing-enhancers >`.
26+
27+ .. code-block :: php
28+
29+ // src/AppBundle/Routing/Enhancer/SimpleEnhancer.php
30+ namespace AppBundle\Routing\Enhancer;
31+
32+ use Symfony\Cmf\Component\Routing\Enhancer\RouteEnhancerInterface;
33+ use Symfony\Component\HttpFoundation\Request;
34+
35+ class SimpleEnhancer implements RouteEnhancerInterface
36+ {
37+ public function enhance(array $defaults, Request $request)
38+ {
39+ // ... customize the $defaults array
40+
41+ return $defaults;
42+ }
43+ }
44+
45+ Simply define services for your enhancers and tag them with
46+ ``dynamic_router_route_enhancer `` to have them added to the routing. You can
47+ specify an optional ``priority `` parameter on the tag to control the order in
48+ which enhancers are executed. The higher the priority, the earlier the enhancer
49+ is executed.
50+
51+ .. configuration-block ::
52+
53+ .. code-block :: yaml
54+
55+ services :
56+ app.routing.simple_enhancer :
57+ class : AppBundle\Routing\Enhancer\SimpleEnhancer
58+ tags :
59+ - { name: dynamic_router_route_enhancer, priority: 10 }
60+
61+ .. code-block :: xml
62+
63+ <?xml version =" 1.0" encoding =" UTF-8" ?>
64+ <container xmlns =" http://symfony.com/schema/dic/services"
65+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
66+ xsi : schemaLocation =" http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd" >
67+
68+ <services >
69+ <service id =" app.routing.simple_enhancer" class =" AppBundle\Routing\Enhancer\SimpleEnhancer" >
70+ <tag name =" dynamic_router_route_enhancer" priority =" 10" />
71+ </service >
72+ </services >
73+ </container >
74+
75+ .. code-block :: php
76+
77+ use Symfony\Component\DependencyInjection\Definition;
78+
79+ $definition = new Definition('AppBundle\Routing\Enhancer\SimpleEnhancer');
80+ $definition->addTag('dynamic_router_route_enhancer', array(
81+ 'priority' => 10,
82+ ));
83+
84+ $container->setDefinition('app.routing.simple_enhancer', $definition);
3085
3186 .. index :: Route Provider
87+
3288.. _bundle-routing-custom_provider :
3389
3490Using a Custom Route Provider
0 commit comments