@@ -12,13 +12,9 @@ conventions or patterns. A great example for this use-case is the
12
12
`FOSRestBundle `_ where routes are generated based on the names of the
13
13
action methods in a controller.
14
14
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.
22
18
23
19
.. note ::
24
20
@@ -57,20 +53,27 @@ its :method:`Symfony\\Component\\Config\\Loader\\LoaderInterface::load` method
57
53
will be called, which should return a :class: `Symfony\\ Component\\ Routing\\ RouteCollection `
58
54
containing :class: `Symfony\\ Component\\ Routing\\ Route ` objects.
59
55
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
+
60
62
Creating a custom Loader
61
63
------------------------
62
64
63
65
To load routes from some custom source (i.e. from something other than annotations,
64
66
YAML or XML files), you need to create a custom route loader. This loader
65
67
has to implement :class: `Symfony\\ Component\\ Config\\ Loader\\ LoaderInterface `.
66
68
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 .
70
72
71
73
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::
74
77
75
78
// src/AppBundle/Routing/ExtraLoader.php
76
79
namespace AppBundle\Routing;
@@ -182,7 +185,7 @@ Using the custom Loader
182
185
~~~~~~~~~~~~~~~~~~~~~~~
183
186
184
187
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:
186
189
187
190
.. configuration-block ::
188
191
0 commit comments