Skip to content

Commit ecfd6d7

Browse files
committed
add constant for controller and use it where applicable. fix symfony#7
1 parent de2ede8 commit ecfd6d7

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

DynamicRouter.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ public function getRouteCollection()
170170
* Returns an array of parameter like this
171171
*
172172
* array(
173-
* "_controller" => "NameSpace\Controller::indexAction",
174-
* "_content" => $document,
173+
* RouteObjectInterface::CONTROLLER_NAME => "NameSpace\Controller::indexAction",
174+
* RouteObjectInterface::CONTENT_OBJECT => $document,
175175
* )
176176
*
177177
* The controller can be either the fully qualified class name or the
@@ -184,7 +184,8 @@ public function getRouteCollection()
184184
* @return array as described above
185185
*
186186
* @throws ResourceNotFoundException If the requested url does not exist in the ODM
187-
* @throws MethodNotAllowedException If the resource was found but the request method is not allowed
187+
* @throws \Symfony\Component\Routing\Exception\MethodNotAllowedException
188+
* If the resource was found but the request method is not allowed
188189
*/
189190
public function match($url)
190191
{
@@ -200,7 +201,7 @@ public function match($url)
200201

201202
$route = $collection->get($defaults['_route']);
202203

203-
if (empty($defaults['_controller'])) {
204+
if (empty($defaults[RouteObjectInterface::CONTROLLER_NAME])) {
204205
// if content does not provide explicit controller, try to find it with one of the mappers
205206
$controller = false;
206207
foreach ($this->mappers as $mapper) {
@@ -214,7 +215,7 @@ public function match($url)
214215
throw new ResourceNotFoundException("The mapper was not able to determine a controller for '$url'");;
215216
}
216217

217-
$defaults['_controller'] = $controller;
218+
$defaults[RouteObjectInterface::CONTROLLER_NAME] = $controller;
218219
}
219220

220221
if ($route instanceof RouteObjectInterface && $content = $route->getRouteContent()) {
@@ -230,7 +231,7 @@ public function match($url)
230231
*
231232
* @param RouteCollection $collection collection of routes for the current request
232233
*
233-
* @return UrlMatcherInterface the url matcher instance
234+
* @return \Symfony\Component\Routing\Matcher\UrlMatcherInterface the url matcher instance
234235
*/
235236
public function getMatcher(RouteCollection $collection)
236237
{

RouteObjectInterface.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ interface RouteObjectInterface
2222
*/
2323
const CONTROLLER_ALIAS = '_controller_alias';
2424

25+
/**
26+
* Field name for an explicit controller name to be used with this route
27+
*/
28+
const CONTROLLER_NAME = '_controller';
29+
2530
/**
2631
* Field name for an explicit template to be used with this route.
2732
* i.e. SymfonyCmfContentBundle:StaticContent:index.html.twig

Tests/Routing/DynamicRouterTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Symfony\Component\Routing\RouteCollection;
66
use Symfony\Cmf\Component\Routing\RouteRepositoryInterface;
7+
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
78
use Symfony\Component\Routing\Route;
89

910
use Symfony\Cmf\Component\Routing\Test\CmfUnitTestCase;
@@ -237,10 +238,10 @@ public function testMatch()
237238
$results = $router->match($url_alias);
238239

239240
$expected = array(
240-
'_controller' => 'NameSpace\\Controller::action',
241+
RouteObjectInterface::CONTROLLER_NAME => 'NameSpace\\Controller::action',
241242
'_route' => DynamicRouter::ROUTE_NAME_PREFIX.'_company_more',
242243
'path' => $url_alias,
243-
'_content' => $this->contentDocument,
244+
RouteObjectInterface::CONTENT_OBJECT => $this->contentDocument,
244245
);
245246

246247
$this->assertEquals($expected, $results);
@@ -278,7 +279,7 @@ public function testNoReferenceMatch()
278279
$router->addControllerMapper($this->mapper);
279280

280281
$expected = array(
281-
'_controller' => 'NameSpace\\Controller::action',
282+
RouteObjectInterface::CONTROLLER_NAME => 'NameSpace\\Controller::action',
282283
'_route' => DynamicRouter::ROUTE_NAME_PREFIX.'_company_more_no_reference',
283284
'path' => $url_alias,
284285
'type' => 'found',

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy