Skip to content

Commit 8b430b5

Browse files
committed
renaming controller resolver to controller mapper. fix https://github.com/symfony-cmf/ChainRoutingBundle/issues/11
1 parent 99acca7 commit 8b430b5

13 files changed

+93
-71
lines changed

DoctrineRouter.php

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use Symfony\Component\Routing\Generator\UrlGenerator;
1212
use Symfony\Component\Routing\Matcher\UrlMatcher;
1313

14-
use Symfony\Cmf\Component\Routing\Resolver\ControllerResolverInterface;
14+
use Symfony\Cmf\Component\Routing\Mapper\ControllerMapperInterface;
1515

1616
use Doctrine\Common\Persistence\ManagerRegistry;
1717
use Doctrine\Common\Persistence\ObjectManager;
@@ -43,19 +43,21 @@ class DoctrineRouter implements RouterInterface
4343
const ROUTE_NAME_PREFIX = 'cmf_routing_doctrine_route';
4444

4545
/**
46-
* @var array of ContentResolverInterface
46+
* @var array of ControllerMapperInterface
4747
*/
48-
protected $resolvers = array();
48+
protected $mappers = array();
4949
/**
5050
* The route repository to get routes from
5151
* @var RouteRepositoryInterface
5252
*/
5353
protected $routeRepository;
5454

5555
/**
56-
* The content repository used to resolve content by it's id
56+
* The content repository used to find content by it's id
5757
* This can be used to specify a parameter content_id when generating urls
5858
*
59+
* This is optional and might not be initialized.
60+
*
5961
* @var ContentRepositoryInterface
6062
*/
6163
protected $contentRepository;
@@ -76,7 +78,7 @@ public function __construct(RouteRepositoryInterface $routeRepository)
7678
}
7779

7880
/**
79-
* Set an optional content repository to resolve content ids
81+
* Set an optional content repository to find content by ids
8082
*
8183
* @param ContentRepositoryInterface $contentRepository
8284
*/
@@ -86,15 +88,15 @@ public function setContentRepository(ContentRepositoryInterface $contentReposito
8688
}
8789

8890
/**
89-
* Add as many resolvers as you want, they are asked for the controller in
91+
* Add as many mappers as you want, they are asked for the controller in
9092
* the order they are added here.
9193
*
92-
* @param ControllerResolverInterface $resolver a helper to resolve the
93-
* controller responsible for the matched url
94+
* @param ControllerMapperInterface $mapper a helper to map the request to
95+
* controller name
9496
*/
95-
public function addControllerResolver(ControllerResolverInterface $resolver)
97+
public function addControllerMapper(ControllerMapperInterface $mapper)
9698
{
97-
$this->resolvers[] = $resolver;
99+
$this->mappers[] = $mapper;
98100
}
99101

100102
/**
@@ -198,17 +200,17 @@ public function match($url)
198200
$route = $collection->get($defaults['_route']);
199201

200202
if (empty($defaults['_controller'])) {
201-
// if content does not provide explicit controller, try to find it with one of the resolvers
203+
// if content does not provide explicit controller, try to find it with one of the mappers
202204
$controller = false;
203-
foreach ($this->resolvers as $resolver) {
204-
$controller = $resolver->getController($route, $defaults);
205+
foreach ($this->mappers as $mapper) {
206+
$controller = $mapper->getController($route, $defaults);
205207
if ($controller !== false) {
206208
break;
207209
}
208210
}
209211

210212
if (false === $controller) {
211-
throw new ResourceNotFoundException("The resolver was not able to determine a controller for '$url'");;
213+
throw new ResourceNotFoundException("The mapper was not able to determine a controller for '$url'");;
212214
}
213215

214216
$defaults['_controller'] = $controller;

Resolver/ControllerAliasResolver.php renamed to Mapper/ControllerAliasMapper.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
<?php
22

3-
namespace Symfony\Cmf\Component\Routing\Resolver;
3+
namespace Symfony\Cmf\Component\Routing\Mapper;
44

55
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
66

77
/**
88
* Decide the controller by a map from alias to controller name injected into
9-
* the resolver.
9+
* the mapper.
1010
* Only works with route objects that return a 'type' field in the defaults.
1111
*
1212
* @author David Buchmann
1313
*/
14-
class ControllerAliasResolver implements ControllerResolverInterface
14+
class ControllerAliasMapper implements ControllerMapperInterface
1515
{
1616
/**
1717
* array containing the mapping between phpcr_alias and controller

Resolver/ControllerClassResolver.php renamed to Mapper/ControllerClassMapper.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
<?php
22

3-
namespace Symfony\Cmf\Component\Routing\Resolver;
3+
namespace Symfony\Cmf\Component\Routing\Mapper;
44

55
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
66

77
/**
88
* Decide the controller by a map from class to controller name injected into
9-
* the resolver. The comparison is done with instanceof to support proxy
9+
* the mapper. The comparison is done with instanceof to support proxy
1010
* classes and such.
1111
*
1212
* Only works with route objects that return a referenced content.
1313
*
1414
* @author David Buchmann
1515
*/
16-
class ControllerClassResolver implements ControllerResolverInterface
16+
class ControllerClassMapper implements ControllerMapperInterface
1717
{
1818
private $controllersByClass;
1919

Resolver/ControllerResolverInterface.php renamed to Mapper/ControllerMapperInterface.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
<?php
22

3-
namespace Symfony\Cmf\Component\Routing\Resolver;
3+
namespace Symfony\Cmf\Component\Routing\Mapper;
44

55
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
66

77
/**
8-
* Interface for all controller resolvers that work with the DoctrineRouter
8+
* Interface for all controller mappers that work with the DoctrineRouter
99
*
1010
* @author David Buchmann
1111
*/
12-
interface ControllerResolverInterface
12+
interface ControllerMapperInterface
1313
{
1414
/**
1515
* Retrieves the right controller for the given route $document.
1616
*
1717
* @param RouteObjectInterface $document the document or entity for the route
1818
* @param array $defaults the getRouteDefaults array which may be altered by
19-
* the resolver
19+
* the mapper
2020
*
2121
* @return string the controller to use with this route object including
2222
* the action, i.e. symfony_cmf_content.controller:indexAction
23-
* or false if the resolver can not determine the router
23+
* or false if the mapper can not determine the router
2424
*/
2525
function getController(RouteObjectInterface $document, array &$defaults);
2626

Resolver/ExplicitTemplateResolver.php renamed to Mapper/ExplicitTemplateMapper.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Symfony\Cmf\Component\Routing\Resolver;
3+
namespace Symfony\Cmf\Component\Routing\Mapper;
44

55
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
66

@@ -10,7 +10,7 @@
1010
*
1111
* @author David Buchmann
1212
*/
13-
class ExplicitTemplateResolver implements ControllerResolverInterface
13+
class ExplicitTemplateMapper implements ControllerMapperInterface
1414
{
1515
/**
1616
* the controller name or service name that will accept a content and a
@@ -21,7 +21,7 @@ class ExplicitTemplateResolver implements ControllerResolverInterface
2121
private $genericController;
2222

2323
/**
24-
* Instantiate the template resolver
24+
* Instantiate the template mapper
2525
*
2626
* @param string $genericController the controller name or service name
2727
* that will accept a content and a template

Resolver/TemplateClassResolver.php renamed to Mapper/TemplateClassMapper.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Symfony\Cmf\Component\Routing\Resolver;
3+
namespace Symfony\Cmf\Component\Routing\Mapper;
44

55
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
66

@@ -12,7 +12,7 @@
1212
*
1313
* @author David Buchmann
1414
*/
15-
class TemplateClassResolver implements ControllerResolverInterface
15+
class TemplateClassMapper implements ControllerMapperInterface
1616
{
1717
/**
1818
* the controller name or service name that will accept a content and a
@@ -30,7 +30,7 @@ class TemplateClassResolver implements ControllerResolverInterface
3030
private $templatesByClass;
3131

3232
/**
33-
* Instantiate the template resolver
33+
* Instantiate the template mapper
3434
*
3535
* @param string $genericController the controller name or service name
3636
* that will accept a content and a template

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ To instantiate a DoctrineRouter, you need an implementation of the
5151
RouteRepositoryInterface. See the [Symfony2 RoutingExtraBundle](https://github.com/symfony-cmf/RoutingExtraBundle)
5252
document classes for an example.
5353

54-
You will want to create controller resolvers that decide what controller will
54+
You will want to create controller mappers that decide what controller will
5555
be used to handle the request, to avoid hardcoding controller names into your
5656
content.
5757

@@ -62,8 +62,8 @@ The match method of the DoctrineRouter does the following steps
6262
* Ask the repository for Route documents that could match the requested url
6363
* Build a route collection and let the UrlMatcher find a matching route
6464
* If the defaults do not contain the field _controller, loop through the
65-
ControllerResolverInterface list to find the controller. If none of the
66-
resolver finds a controller, throw a ResourceNotFoundException
65+
ControllerMapperInterface list to find the controller. If none of the
66+
mapper finds a controller, throw a ResourceNotFoundException
6767
* If the route implements RouteObjectInterace and returns a non-null content,
6868
set it in the returned array with key ``_content``.
6969

@@ -78,7 +78,7 @@ All routes still need to extend the base class Symfony\Component\Routing\Route
7878
You can build redirections with a RedirectRouteInterface document. It can
7979
redirect either to an absolute URI, or to a named route that can be generated by
8080
any router in the chain or to another Route object in the repository.
81-
To handle it, you can make ControllerClassResolver map a suitable controller
81+
To handle it, you can make ControllerClassMapper map a suitable controller
8282
to Symfony\Cmf\Component\Routing\RedirectRouteInterface
8383

8484
### Routes and locales
@@ -96,7 +96,7 @@ under the same url is not a good idea.
9696

9797
### Customize
9898

99-
You can add more ControllerResolverInterface implementations if you have a case
99+
You can add more ControllerMapperInterface implementations if you have a case
100100
not handled by the provided ones.
101101

102102
For more specific needs, have a look at DoctrineRouter and see if you want to

RouteObjectInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
interface RouteObjectInterface
1414
{
1515
/**
16-
* Constant for the field that is given to the ControllerAliasResolver.
16+
* Constant for the field that is given to the ControllerAliasMapper.
1717
* The value must be configured in the controllers_by_alias mapping.
1818
*
1919
* This is ignored if a _controller default value is provided as well
@@ -28,7 +28,7 @@ interface RouteObjectInterface
2828

2929
/**
3030
* Get the content document this route entry stands for. If non-null,
31-
* the ControllerClassResolver uses it to identify a controller and
31+
* the ControllerClassMapper uses it to identify a controller and
3232
* the content is passed to the controller.
3333
*
3434
* If there is no specific content for this url (i.e. its an "application"

Tests/Resolver/ControllerAliasResolverTest.php renamed to Tests/Mapper/ControllerAliasMapperTest.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,40 @@
33
namespace Symfony\Cmf\Component\Routing\Tests\Controller;
44

55
use Symfony\Cmf\Component\Routing\Test\CmfUnitTestCase;
6-
use Symfony\Cmf\Component\Routing\Resolver\ControllerAliasResolver;
6+
use Symfony\Cmf\Component\Routing\Mapper\ControllerAliasMapper;
77

8-
class ControllerAliasResolverTest extends CmfUnitTestCase
8+
class ControllerAliasMapperTest extends CmfUnitTestCase
99
{
10+
/**
11+
* @var ControllerAliasMapper
12+
*/
13+
private $mapper;
14+
1015
public function setUp()
1116
{
1217
$this->document = $this->buildMock('Symfony\\Cmf\\Component\\Routing\\RouteObjectInterface',
1318
array('getRouteContent', 'getRouteDefaults', 'getUrl'));
1419

1520
$mapping = array('static_pages' => 'symfony_cmf_content.controller:indexAction');
1621

17-
$this->resolver = new ControllerAliasResolver($mapping);
22+
$this->mapper = new ControllerAliasMapper($mapping);
1823
}
1924

2025
public function testControllerFoundInMapping()
2126
{
2227
$defaults = array('type' => 'static_pages');
23-
$this->assertEquals('symfony_cmf_content.controller:indexAction', $this->resolver->getController($this->document, $defaults));
28+
$this->assertEquals('symfony_cmf_content.controller:indexAction', $this->mapper->getController($this->document, $defaults));
2429
}
2530

2631
public function testControllerNoType()
2732
{
2833
$defaults = array();
29-
$this->assertEquals(null, $this->resolver->getController($this->document, $defaults));
34+
$this->assertEquals(null, $this->mapper->getController($this->document, $defaults));
3035
}
3136

3237
public function testControllerNotFoundInMapping()
3338
{
3439
$defaults = array('type' => 'unknown_route');
35-
$this->assertEquals(null, $this->resolver->getController($this->document, $defaults));
40+
$this->assertEquals(null, $this->mapper->getController($this->document, $defaults));
3641
}
3742
}

Tests/Resolver/ControllerClassResolverTest.php renamed to Tests/Mapper/ControllerClassMapperTest.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@
33
namespace Symfony\Cmf\Component\Routing\Tests\Controller;
44

55
use Symfony\Cmf\Component\Routing\Test\CmfUnitTestCase;
6-
use Symfony\Cmf\Component\Routing\Resolver\ControllerClassResolver;
6+
use Symfony\Cmf\Component\Routing\Mapper\ControllerClassMapper;
77

8-
class ControllerClassResolverTest extends CmfUnitTestCase
8+
class ControllerClassMapperTest extends CmfUnitTestCase
99
{
10+
/**
11+
* @var ControllerClassMapper
12+
*/
13+
private $mapper;
14+
1015
public function setUp()
1116
{
1217
$this->document = $this->buildMock('Symfony\\Cmf\\Component\\Routing\\RouteObjectInterface',
@@ -15,7 +20,7 @@ public function setUp()
1520
$mapping = array('Symfony\\Cmf\\Component\\Routing\\Tests\\Controller\\TargetDocument'
1621
=> 'symfony_cmf_content.controller:indexAction');
1722

18-
$this->resolver = new ControllerClassResolver($mapping);
23+
$this->mapper = new ControllerClassMapper($mapping);
1924
}
2025

2126
public function testControllerFoundInMapping()
@@ -25,7 +30,7 @@ public function testControllerFoundInMapping()
2530
->will($this->returnValue(new TargetDocument));
2631

2732
$defaults = array();
28-
$this->assertEquals('symfony_cmf_content.controller:indexAction', $this->resolver->getController($this->document, $defaults));
33+
$this->assertEquals('symfony_cmf_content.controller:indexAction', $this->mapper->getController($this->document, $defaults));
2934
$this->assertEquals(array(), $defaults);
3035
}
3136

@@ -36,7 +41,7 @@ public function testControllerNotFoundInMapping()
3641
->will($this->returnValue(new UnknownDocument));
3742

3843
$defaults = array();
39-
$this->assertEquals(null, $this->resolver->getController($this->document, $defaults));
44+
$this->assertEquals(null, $this->mapper->getController($this->document, $defaults));
4045
$this->assertEquals(array(), $defaults);
4146
}
4247

@@ -47,7 +52,7 @@ public function testControllerNoContent()
4752
->will($this->returnValue(null));
4853

4954
$defaults = array();
50-
$this->assertEquals(null, $this->resolver->getController($this->document, $defaults));
55+
$this->assertEquals(null, $this->mapper->getController($this->document, $defaults));
5156
$this->assertEquals(array(), $defaults);
5257
}
5358
}

0 commit comments

Comments
 (0)