Skip to content
This repository was archived by the owner on Sep 16, 2021. It is now read-only.

Commit dbcad64

Browse files
andrey1swouterj
andrey1s
authored andcommitted
add example Writing your own Route Enhancers
1 parent e6f0a92 commit dbcad64

File tree

1 file changed

+51
-3
lines changed

1 file changed

+51
-3
lines changed

bundles/routing/dynamic_customize.rst

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,59 @@ Writing your own Route Enhancers
2222

2323
You can add your own :ref:`RouteEnhancerInterface <bundles-routing-dynamic_router-enhancer>`
2424
implementations 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.
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+
34+
class SimpleEnhancer implements RouteEnhancerInterface
35+
{
36+
}
37+
38+
39+
Simply define services for your enhancers and tag them with ``dynamic_router_route_enhancer`` to have
40+
them added to the routing. You can specify an optional ``priority`` parameter
41+
on the tag to control the order in which enhancers are executed. The higher the
42+
priority, the earlier the enhancer is executed.
43+
44+
.. configuration-block::
45+
46+
.. code-block:: yaml
47+
48+
services:
49+
app.routing.enhancer.simple:
50+
class: AppBundle\Routing\Enhancer\SimpleEnhancer
51+
tags:
52+
- { name: dynamic_router_route_enhancer priority: 10 }
53+
54+
.. code-block:: xml
55+
56+
<?xml version="1.0" encoding="UTF-8" ?>
57+
<container xmlns="http://symfony.com/schema/dic/services"
58+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
59+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
60+
61+
<services>
62+
<service id="app.routing.enhancer.simple" class="AppBundle\Routing\Enhancer\SimpleEnhancer">
63+
<tag name="dynamic_router_route_enhancer" priority="10" />
64+
</service>
65+
</services>
66+
</container>
67+
68+
.. code-block:: php
69+
70+
use Symfony\Component\DependencyInjection\Definition;
71+
72+
$definitionSendmail = new Definition('AppBundle\Routing\Enhancer\SimpleEnhancer');
73+
$definitionSendmail->addTag('dynamic_router_route_enhancer',array('priority' => 10));
74+
$container->setDefinition('app.routing.enhancer.simple', $definitionSendmail);
2875
2976
.. index:: Route Provider
77+
3078
.. _bundle-routing-custom_provider:
3179

3280
Using a Custom Route Provider

0 commit comments

Comments
 (0)