Skip to content
This repository was archived by the owner on Sep 16, 2021. It is now read-only.

Commit 9eb0a46

Browse files
author
dantleech
committed
Updated style and contents
1 parent df03433 commit 9eb0a46

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

cookbook/using-a-custom-route-repository.rst

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
Using a custom route repository with Dynmaic Router
22
===================================================
33

4-
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.
57

68
Creating the route repository
79
-----------------------------
810

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.
1018

1119
.. code-block:: php
1220
@@ -16,15 +24,20 @@ The route repository must implement the `RouteRepositoryInterface` and in additi
1624
use Doctrine\ODM\PHPCR\DocumentRepository;
1725
use Symfony\Cmf\Component\Routing\RouteRepositoryInterface;
1826
use Symfony\Component\Routing\RouteCollection;
27+
use Symfony\Component\Routing\Route as SymfonyRoute;
1928
2029
class RouteRepository extends DocumentRepository implements RouteRepositoryInterface
2130
2231
{
2332
public function findManyByUrl($url)
2433
{
25-
$route = $this->findOneBy(array(
34+
$myDocument = $this->findOneBy(array(
2635
'path' => $url,
2736
));
37+
38+
$pattern = $myDocument->getUrl(); // e.g. "/this/is/a/route"
39+
40+
$route = new SymfonyRoute($pattern);
2841
$collection = new RouteCollection(array($route));
2942
3043
return $collection;
@@ -43,8 +56,9 @@ The route repository must implement the `RouteRepositoryInterface` and in additi
4356
The route class
4457
---------------
4558

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.
4862

4963
.. code-block:: php
5064
@@ -53,20 +67,21 @@ As noted above, the route classes provided by the route repository must *extend
5367
namespace MyVendor\Bundle\MyBundle\Document;
5468
use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCR;
5569
use DCMS\Bundle\CoreBundle\Validation\Constraints as RoutingValidation;
56-
use Symfony\Component\Routing\Route as BaseRoute;
70+
use Symfony\Component\Routing\Route as SymfonyRoute;
5771
5872
/**
5973
* @PHPCR\Document(repositoryClass="MyVendor\Bundle\MyBundle\Repository\RouteRepository")
6074
*/
61-
class Route extends BaseRoute
75+
class Route extends SymfonyRoute
6276
{
6377
// @todo: Fill this out
6478
}
6579
6680
Replacing the default CMF repository
6781
------------------------------------
6882

69-
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:
7085

7186
.. code-block:: yaml
7287
@@ -76,4 +91,6 @@ The final step is to replace the default CMF routing repository service with you
7691
enabled: true
7792
route_repository_service_id: my_bundle.repository.endpoint
7893
79-
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/>`_
96+
for information on creating custom services.

index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ Special solutions for special needs that go beyond standard usage.
5555
:maxdepth: 1
5656

5757
cookbook/phpcr-odm-custom-documentclass-mapper
58+
cookbook/using-a-custom-route-repository
5859

5960
Components
6061
----------

0 commit comments

Comments
 (0)