This repository was archived by the owner on Sep 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 156
add example Writing your own Route Enhancers #744
Closed
Closed
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,12 +22,62 @@ Writing your own Route Enhancers | |
|
||
You can add your own :ref:`RouteEnhancerInterface <bundles-routing-dynamic_router-enhancer>` | ||
implementations if you have a case not handled by the | ||
:ref:`provided enhancers <component-routing-enhancers>`. Simply define services | ||
for your enhancers and tag them with ``dynamic_router_route_enhancer`` to have | ||
:ref:`provided enhancers <component-routing-enhancers>`. | ||
|
||
.. code-block:: php | ||
|
||
// src/AppBundle/Routing/Enhancer/SimpleEnhancer.php | ||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's show that one has to return the new defaults array like this: public function enhance(array $defaults, Request $request)
{
// ... tweak the $defaults array
return $defaults;
} |
||
} | ||
} | ||
|
||
|
||
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 } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing |
||
|
||
.. code-block:: xml | ||
|
||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<container xmlns="http://symfony.com/schema/dic/services" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> | ||
|
||
<services> | ||
<service id="app.routing.enhancer.simple" class="AppBundle\Routing\Enhancer\SimpleEnhancer"> | ||
<tag name="dynamic_router_route_enhancer" priority="10" /> | ||
</service> | ||
</services> | ||
</container> | ||
|
||
.. code-block:: php | ||
|
||
use Symfony\Component\DependencyInjection\Definition; | ||
|
||
$definitionSendmail = new Definition('AppBundle\Routing\Enhancer\SimpleEnhancer'); | ||
$definitionSendmail->addTag('dynamic_router_route_enhancer',array('priority' => 10)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the variable seems to be a copy-paste mistake. Let's rename it to simply |
||
$container->setDefinition('app.routing.enhancer.simple', $definitionSendmail); | ||
|
||
.. index:: Route Provider | ||
.. _bundle-routing-custom_provider: | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this code would be invalid, we should add a method that does something trivial to make the example complete.