From 903410ab61db2f8e9c969a579acd51e808c67ac7 Mon Sep 17 00:00:00 2001 From: andrey1s <“andrey@4devs.pro”> Date: Fri, 26 Feb 2016 14:05:15 +0300 Subject: [PATCH 1/4] add example Writing your own Route Enhancers --- bundles/routing/dynamic_customize.rst | 49 +++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/bundles/routing/dynamic_customize.rst b/bundles/routing/dynamic_customize.rst index 0edeb65d..1b2aefe8 100644 --- a/bundles/routing/dynamic_customize.rst +++ b/bundles/routing/dynamic_customize.rst @@ -22,12 +22,57 @@ Writing your own Route Enhancers You can add your own :ref:`RouteEnhancerInterface ` implementations if you have a case not handled by the -:ref:`provided enhancers `. Simply define services -for your enhancers and tag them with ``dynamic_router_route_enhancer`` to have +:ref:`provided enhancers `. + +.. code-block:: php + + // src/AppBundle/Routing/Enhancer/SimpleEnhancer.php + namespace AppBundle\Routing\Enhancer; + + use Symfony\Cmf\Component\Routing\Enhancer\RouteEnhancerInterface; + + class SimpleEnhancer implements RouteEnhancerInterface + { + } + + +Simply define services for your enhancers and tag them with ``dynamic_router_route_enhancer`` to have them added to the routing. You can specify an optional ``priority`` parameter on the tag to control the order in which enhancers are executed. The higher the priority, the earlier the enhancer is executed. +.. configuration-block:: + + .. code-block:: yaml + + services: + app.routing.enhancer.simple: + class: AppBundle\Routing\Enhancer\SimpleEnhancer + tags: + - { name: dynamic_router_route_enhancer priority: 10 } + + .. code-block:: xml + + + + + + + + + + + + .. code-block:: php + + use Symfony\Component\DependencyInjection\Definition; + + $definitionSendmail = new Definition('AppBundle\Routing\Enhancer\SimpleEnhancer'); + $definitionSendmail->addTag('dynamic_router_route_enhancer',array('priority' => 10)); + $container->setDefinition('app.routing.enhancer.simple', $definitionSendmail); + .. index:: Route Provider .. _bundle-routing-custom_provider: From a61c78a196444decdc32cbc234cfcbfa3726f7c3 Mon Sep 17 00:00:00 2001 From: andrey1s <“andrey@4devs.pro”> Date: Sat, 27 Feb 2016 11:57:02 +0300 Subject: [PATCH 2/4] implement method fir example Route Enhancers --- bundles/routing/dynamic_customize.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/bundles/routing/dynamic_customize.rst b/bundles/routing/dynamic_customize.rst index 1b2aefe8..e28783ea 100644 --- a/bundles/routing/dynamic_customize.rst +++ b/bundles/routing/dynamic_customize.rst @@ -30,9 +30,14 @@ implementations if you have a case not handled by the namespace AppBundle\Routing\Enhancer; use Symfony\Cmf\Component\Routing\Enhancer\RouteEnhancerInterface; + use Symfony\Component\HttpFoundation\Request; class SimpleEnhancer implements RouteEnhancerInterface { + public function enhance(array $defaults, Request $request) + { + //own logic + } } From 49909f1783a6031911499d039d285c2f78b7786e Mon Sep 17 00:00:00 2001 From: andrey1s <“andrey@4devs.pro”> Date: Sat, 27 Feb 2016 23:04:15 +0300 Subject: [PATCH 3/4] fix define service --- bundles/routing/dynamic_customize.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bundles/routing/dynamic_customize.rst b/bundles/routing/dynamic_customize.rst index e28783ea..35e80263 100644 --- a/bundles/routing/dynamic_customize.rst +++ b/bundles/routing/dynamic_customize.rst @@ -54,7 +54,7 @@ priority, the earlier the enhancer is executed. app.routing.enhancer.simple: class: AppBundle\Routing\Enhancer\SimpleEnhancer tags: - - { name: dynamic_router_route_enhancer priority: 10 } + - { name: dynamic_router_route_enhancer, priority: 10 } .. code-block:: xml @@ -74,9 +74,9 @@ priority, the earlier the enhancer is executed. use Symfony\Component\DependencyInjection\Definition; - $definitionSendmail = new Definition('AppBundle\Routing\Enhancer\SimpleEnhancer'); - $definitionSendmail->addTag('dynamic_router_route_enhancer',array('priority' => 10)); - $container->setDefinition('app.routing.enhancer.simple', $definitionSendmail); + $definition = new Definition('AppBundle\Routing\Enhancer\SimpleEnhancer'); + $definition->addTag('dynamic_router_route_enhancer',array('priority' => 10)); + $container->setDefinition('app.routing.enhancer.simple', $definition); .. index:: Route Provider .. _bundle-routing-custom_provider: From fe43f1fab21f3c3cb203731e833190b9cb159794 Mon Sep 17 00:00:00 2001 From: andrey1s <“andrey@4devs.pro”> Date: Sat, 27 Feb 2016 23:12:34 +0300 Subject: [PATCH 4/4] add return SimpleEnhancer::enhance --- bundles/routing/dynamic_customize.rst | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bundles/routing/dynamic_customize.rst b/bundles/routing/dynamic_customize.rst index 35e80263..d36e5bfe 100644 --- a/bundles/routing/dynamic_customize.rst +++ b/bundles/routing/dynamic_customize.rst @@ -36,7 +36,10 @@ implementations if you have a case not handled by the { public function enhance(array $defaults, Request $request) { - //own logic + // own logic. + + // Enhancer MUST return the $defaults but may add or remove values. + return $defaults; } }