Skip to content

Commit fe1a574

Browse files
committed
Change code example to extend from Loader class
1 parent bd6e3f3 commit fe1a574

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

cookbook/routing/custom_route_loader.rst

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,21 @@ To load routes from some custom source (i.e. from something other than annotatio
6464
YAML or XML files), you need to create a custom route loader. This loader
6565
has to implement :class:`Symfony\\Component\\Config\\Loader\\LoaderInterface`.
6666

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`.
70+
6771
The sample loader below supports loading routing resources with a type of
6872
``extra``. The type ``extra`` isn't important - you can just invent any resource
6973
type you want. The resource name itself is not actually used in the example::
7074

7175
namespace AppBundle\Routing;
7276

73-
use Symfony\Component\Config\Loader\LoaderInterface;
74-
use Symfony\Component\Config\Loader\LoaderResolverInterface;
77+
use Symfony\Component\Config\Loader\Loader;
7578
use Symfony\Component\Routing\Route;
7679
use Symfony\Component\Routing\RouteCollection;
7780

78-
class ExtraLoader implements LoaderInterface
81+
class ExtraLoader extends Loader
7982
{
8083
private $loaded = false;
8184

@@ -110,17 +113,6 @@ type you want. The resource name itself is not actually used in the example::
110113
{
111114
return 'extra' === $type;
112115
}
113-
114-
public function getResolver()
115-
{
116-
// needed, but can be blank, unless you want to load other resources
117-
// and if you do, using the Loader base class is easier (see below)
118-
}
119-
120-
public function setResolver(LoaderResolverInterface $resolver)
121-
{
122-
// same as above
123-
}
124116
}
125117

126118
Make sure the controller you specify really exists. In this case you
@@ -130,6 +122,7 @@ of the ``AppBundle``::
130122
namespace AppBundle\Controller;
131123

132124
use Symfony\Component\HttpFoundation\Response;
125+
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
133126

134127
class ExtraController extends Controller
135128
{
@@ -232,11 +225,10 @@ for the ``ExtraLoader``, so it is set to ".".
232225
More advanced Loaders
233226
---------------------
234227

235-
In most cases it's better not to implement
236-
:class:`Symfony\\Component\\Config\\Loader\\LoaderInterface`
237-
yourself, but extend from :class:`Symfony\\Component\\Config\\Loader\\Loader`.
238-
This class knows how to use a
239-
:class:`Symfony\\Component\\Config\\Loader\\LoaderResolver` to load secondary
228+
If your custom route loader extends from
229+
:class:`Symfony\\Component\\Config\\Loader\\Loader` as shown above, you
230+
can also make use of the provided resolver, an instance of
231+
:class:`Symfony\\Component\\Config\\Loader\\LoaderResolver`, to load secondary
240232
routing resources.
241233

242234
Of course you still need to implement

0 commit comments

Comments
 (0)