You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Sep 16, 2021. It is now read-only.
The Dynamic Router allows you to customize the route Repository (i.e. the class responsible for retrieving routes from the database), and by extension, the Route objects.
4
+
The Dynamic Router allows you to customize the route Repository (i.e. the class
5
+
responsible for retrieving routes from the database), and by extension, the
6
+
Route objects.
5
7
6
8
Creating the route repository
7
9
-----------------------------
8
10
9
-
The route repository must implement the `RouteRepositoryInterface` and in addition should return objects which extend the Symfony Route class. The following class provides a simple solution which uses an ODM Repository, but you can equally imagine an ORM repository or indeed anything you like, as long as it implements the interface.
11
+
The route repository must implement the `RouteRepositoryInterface` and in
12
+
addition should return instances of the Symfony Route class. The
13
+
following class provides a simple solution using an ODM Repository. For the
14
+
purpose of example we create the Symfony Route object and map the pattern
15
+
to it directly.
16
+
17
+
Why return multiple routes? .. @todo explain that here.
10
18
11
19
.. code-block:: php
12
20
@@ -16,15 +24,20 @@ The route repository must implement the `RouteRepositoryInterface` and in additi
16
24
use Doctrine\ODM\PHPCR\DocumentRepository;
17
25
use Symfony\Cmf\Component\Routing\RouteRepositoryInterface;
18
26
use Symfony\Component\Routing\RouteCollection;
27
+
use Symfony\Component\Routing\Route as SymfonyRoute;
19
28
20
29
class RouteRepository extends DocumentRepository implements RouteRepositoryInterface
21
30
22
31
{
23
32
public function findManyByUrl($url)
24
33
{
25
-
$route = $this->findOneBy(array(
34
+
$myDocument = $this->findOneBy(array(
26
35
'path' => $url,
27
36
));
37
+
38
+
$pattern = $myDocument->getUrl(); // e.g. "/this/is/a/route"
39
+
40
+
$route = new SymfonyRoute($pattern);
28
41
$collection = new RouteCollection(array($route));
29
42
30
43
return $collection;
@@ -43,8 +56,9 @@ The route repository must implement the `RouteRepositoryInterface` and in additi
43
56
The route class
44
57
---------------
45
58
46
-
As noted above, the route classes provided by the route repository must *extend* `Symfony\Component\Routing\Route` and provide whatever other parameters required by the storage engine, the following is an example ODM object:
47
-
59
+
As noted above, the route classes provided by the route repository must
60
+
be instances of `Symfony\Component\Routing\Route`. A good pattern is to
61
+
have your ODM/ORM/Other Document extend the Symfony Route class.
48
62
49
63
.. code-block:: php
50
64
@@ -53,20 +67,21 @@ As noted above, the route classes provided by the route repository must *extend
53
67
namespace MyVendor\Bundle\MyBundle\Document;
54
68
use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCR;
55
69
use DCMS\Bundle\CoreBundle\Validation\Constraints as RoutingValidation;
56
-
use Symfony\Component\Routing\Route as BaseRoute;
70
+
use Symfony\Component\Routing\Route as SymfonyRoute;
The final step is to replace the default CMF routing repository service with your own. This is easily accomplished using the application configuration:
83
+
The final step is to replace the default CMF routing repository service with
84
+
your own. This is easily accomplished using the application configuration:
70
85
71
86
.. code-block:: yaml
72
87
@@ -76,4 +91,6 @@ The final step is to replace the default CMF routing repository service with you
Where `my_bundle.repository.endpoint` is the service ID of your repository. See `Creating and configuring services in the container <http://symfony.com/doc/current/book/service_container.html#creating-configuring-services-in-the-container/>`_ for information on creating custom services.
94
+
Where `my_bundle.repository.endpoint` is the service ID of your repository.
95
+
See `Creating and configuring services in the container <http://symfony.com/doc/current/book/service_container.html#creating-configuring-services-in-the-container/>`_
0 commit comments