Skip to content

Commit febe3e3

Browse files
Processed feedback by @lazyhammer and @wouterj
1 parent c1cd667 commit febe3e3

File tree

1 file changed

+32
-10
lines changed

1 file changed

+32
-10
lines changed

cookbook/routing/custom_route_loader.rst

+32-10
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ How to Create a Custom Route Loader
77
Loading Routes
88
--------------
99

10-
The routes in a Symfony application are loaded by the :class:`Symfony\\Bundle\\FrameworkBundle\\Routing\\DelegatingLoader`.
10+
The routes in a Symfony application are loaded by the
11+
:class:`Symfony\\Bundle\\FrameworkBundle\\Routing\\DelegatingLoader`.
1112
This loader uses several other loaders (delegates) to load resources of
1213
different types, for instance Yaml files or ``@Route`` and ``@Method`` annotations
1314
in controller files. The specialized loaders implement :class:`Symfony\\Component\\Config\\Loader\\LoaderInterface`
@@ -25,7 +26,7 @@ Take these lines from ``routing.yml``:
2526
2627
The main loader tries all the delegate loaders and calls their
2728
:method:`Symfony\\Component\\Config\\Loader\\LoaderInterface::supports`
28-
with the given resource ("@AcmeDemoBundle/Controller/DemoController.php")
29+
with the given resource (``@AcmeDemoBundle/Controller/DemoController.php``)
2930
and type ("annotation") as arguments. When one of the loader returns ``true``,
3031
its method :method:`Symfony\\Component\\Config\\Loader\\LoaderInterface::load`
3132
will be called, and the loader returns a :class:`Symfony\\Component\\Routing\\RouteCollection`
@@ -34,14 +35,14 @@ containing :class:`Symfony\\Component\\Routing\\Route` objects.
3435
Creating a Custom Loader
3536
------------------------
3637

37-
To load routes in another way then using annotations, Yaml or XML files,
38+
To load routes in another way than using annotations, Yaml or XML files,
3839
you need to create a custom route loader. This loader should implement
3940
:class:`Symfony\\Component\\Config\\Loader\\LoaderInterface`.
4041

4142
The sample loader below supports resources of type "extra". The resource
4243
name itself is not used in the example::
4344

44-
namespace Acme\DemoBundleBundle\Routing;
45+
namespace Acme\DemoBundle\Routing;
4546

4647
use Symfony\Component\Config\Loader\LoaderInterface;
4748
use Symfony\Component\Config\Loader\LoaderResolver;
@@ -118,7 +119,7 @@ Now define a service for the ``ExtraLoader``:
118119
119120
<services>
120121
<service id="acme_demo.routing_loader" class="Acme\DemoBundle\Routing\ExtraLoader">
121-
<tag name="routing.loader"></tag>
122+
<tag name="routing.loader" />
122123
</service>
123124
</services>
124125
</container>
@@ -139,13 +140,34 @@ Notice the tag ``routing.loader``. All services with this tag will be marked
139140
as potential route loaders and added as specialized routers to the
140141
:class:`Symfony\\Bundle\\FrameworkBundle\\Routing\\DelegatingLoader`.
141142

142-
Finally, we only need to add a few extra lines in ``routing.yml``:
143+
Finally, we only need to add a few extra lines to the routing configuration:
143144

144-
.. code-block:: yaml
145+
.. configuration-block::
146+
147+
.. code-block:: yaml
148+
149+
AcmeDemoBundle_Extra:
150+
resource: .
151+
type: extra
152+
153+
.. code-block:: xml
154+
155+
<?xml version="1.0" encoding="UTF-8" ?>
156+
<routes xmlns="http://symfony.com/schema/routing"
157+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
158+
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
159+
160+
<import resource="." type="extra" />
161+
</routes>
162+
163+
.. code-block:: php
164+
165+
use Symfony\Component\Routing\RouteCollection;
166+
167+
$collection = new RouteCollection();
168+
$collection->addCollection($loader->import('.', 'extra'));
145169
146-
AcmeDemoBundle_Extra:
147-
resource: .
148-
type: extra
170+
return $collection;
149171
150172
The ``resource`` key is irrelevant, but required. The important part here
151173
is the ``type`` key. Its value should be "extra". This is the type which

0 commit comments

Comments
 (0)