Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Symfony/Component/Routing/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ CHANGELOG
3.4.0
-----

* Added the possibility to define a prefix for all routes of a controller via @Route(name="prefix_")
* Added support for prioritized routing loaders.
* Add matched and default parameters to redirect responses
* Added support for a `controller` keyword for configuring route controllers in YAML and XML configurations.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ public function load($class, $type = null)

if (0 === $collection->count() && $class->hasMethod('__invoke') && $annot = $this->reader->getClassAnnotation($class, $this->routeAnnotationClass)) {
$globals['path'] = '';
$globals['name'] = '';
$this->addRoute($collection, $annot, $globals, $class, $class->getMethod('__invoke'));
}

Expand All @@ -141,6 +142,7 @@ protected function addRoute(RouteCollection $collection, $annot, $globals, \Refl
if (null === $name) {
$name = $this->getDefaultRouteName($class, $method);
}
$name = $globals['name'].$name;

$defaults = array_replace($globals['defaults'], $annot->getDefaults());
foreach ($method->getParameters() as $param) {
Expand Down Expand Up @@ -222,9 +224,14 @@ protected function getGlobals(\ReflectionClass $class)
'methods' => array(),
'host' => '',
'condition' => '',
'name' => '',
);

if ($annot = $this->reader->getClassAnnotation($class, $this->routeAnnotationClass)) {
if (null !== $annot->getName()) {
$globals['name'] = $annot->getName();
}

if (null !== $annot->getPath()) {
$globals['path'] = $annot->getPath();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ public function testLoad($className, $routeData = array(), $methodArgs = array()
public function testClassRouteLoad()
{
$classRouteData = array(
'name' => 'prefix_',
'path' => '/prefix',
'schemes' => array('https'),
'methods' => array('GET'),
Expand All @@ -173,7 +174,7 @@ public function testClassRouteLoad()
;

$routeCollection = $this->loader->load('Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BarClass');
$route = $routeCollection->get($methodRouteData['name']);
$route = $routeCollection->get($classRouteData['name'].$methodRouteData['name']);

$this->assertSame($classRouteData['path'].$methodRouteData['path'], $route->getPath(), '->load concatenates class and method route path');
$this->assertEquals(array_merge($classRouteData['schemes'], $methodRouteData['schemes']), $route->getSchemes(), '->load merges class and method route schemes');
Expand Down Expand Up @@ -240,7 +241,7 @@ public function testInvokableClassWithMethodRouteLoad()

$this->assertNull($route, '->load ignores class route');

$route = $routeCollection->get($methodRouteData['name']);
$route = $routeCollection->get($classRouteData['name'].$methodRouteData['name']);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, that's a BC break, but I don't think this matters much as someone defining a class with an __invoke method would probably not define a name on the class @Route annotation (I don't see the point).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're right, because it would have to map to the __invoke method, even if @Route() was used for the service definition.


$this->assertSame($classRouteData['path'].$methodRouteData['path'], $route->getPath(), '->load concatenates class and method route path');
$this->assertEquals(array_merge($classRouteData['schemes'], $methodRouteData['schemes']), $route->getSchemes(), '->load merges class and method route schemes');
Expand Down