Skip to content

Commit 762351e

Browse files
committed
clarify custom route loader documentation
1 parent 523d08c commit 762351e

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

cookbook/routing/custom_route_loader.rst

+16-13
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,9 @@ conventions or patterns. A great example for this use-case is the
1212
`FOSRestBundle`_ where routes are generated based on the names of the
1313
action methods in a controller.
1414

15-
A custom route loader does not enable your bundle to inject routes
16-
without the need to modify the routing configuration
17-
(e.g. ``app/config/routing.yml``) manually.
18-
If your bundle provides routes, whether via a configuration file, like
19-
the `WebProfilerBundle` does, or via a custom route loader, like the
20-
`FOSRestBundle`_ does, an entry in the routing configuration is always
21-
necessary.
15+
You still need to modify your routing configuration (e.g.
16+
``app/config/routing.yml``) manually, even when using a custom route
17+
loader.
2218

2319
.. note::
2420

@@ -57,20 +53,27 @@ its :method:`Symfony\\Component\\Config\\Loader\\LoaderInterface::load` method
5753
will be called, which should return a :class:`Symfony\\Component\\Routing\\RouteCollection`
5854
containing :class:`Symfony\\Component\\Routing\\Route` objects.
5955

56+
.. note::
57+
58+
Routes loaded this way will be cached by the Router the same way as
59+
when they are defined in one of the default formats (e.g. XML, YML,
60+
PHP file).
61+
6062
Creating a custom Loader
6163
------------------------
6264

6365
To load routes from some custom source (i.e. from something other than annotations,
6466
YAML or XML files), you need to create a custom route loader. This loader
6567
has to implement :class:`Symfony\\Component\\Config\\Loader\\LoaderInterface`.
6668

67-
In most cases it's better not to implement
68-
:class:`Symfony\\Component\\Config\\Loader\\LoaderInterface`
69-
yourself, but extend from :class:`Symfony\\Component\\Config\\Loader\\Loader`.
69+
In most cases it is easier to extend from
70+
:class:`Symfony\\Component\\Config\\Loader\\Loader` instead of implementing
71+
:class:`Symfony\\Component\\Config\\Loader\\LoaderInterface` yourself.
7072

7173
The sample loader below supports loading routing resources with a type of
72-
``extra``. The type ``extra`` isn't important - you can just invent any resource
73-
type you want. The resource name itself is not actually used in the example::
74+
``extra``. The type name should not clash with other loaders that might
75+
support the same type of resource. Just make up a name specific to what
76+
you do. The resource name itself is not actually used in the example::
7477

7578
// src/AppBundle/Routing/ExtraLoader.php
7679
namespace AppBundle\Routing;
@@ -182,7 +185,7 @@ Using the custom Loader
182185
~~~~~~~~~~~~~~~~~~~~~~~
183186

184187
If you did nothing else, your custom routing loader would *not* be called.
185-
Instead, you only need to add a few extra lines to the routing configuration:
188+
What remains to do is adding a few lines to the routing configuration:
186189

187190
.. configuration-block::
188191

0 commit comments

Comments
 (0)