Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ff9a6bf

Browse filesBrowse files
committed
[Routing] added the possibility to define a prefix for all routes of a controller
1 parent b9fc357 commit ff9a6bf
Copy full SHA for ff9a6bf

File tree

3 files changed

+9
-0
lines changed
Filter options

3 files changed

+9
-0
lines changed

‎src/Symfony/Component/Routing/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CHANGELOG
44
3.4.0
55
-----
66

7+
* Added the possibility to define a prefix for all routes of a controller via @Route(name="prefix_")
78
* Added support for prioritized routing loaders.
89
* Add matched and default parameters to redirect responses
910
* Added support for a `controller` keyword for configuring route controllers in YAML and XML configurations.

‎src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ protected function addRoute(RouteCollection $collection, $annot, $globals, \Refl
141141
if (null === $name) {
142142
$name = $this->getDefaultRouteName($class, $method);
143143
}
144+
$name = $globals['name'].$name;
144145

145146
$defaults = array_replace($globals['defaults'], $annot->getDefaults());
146147
foreach ($method->getParameters() as $param) {
@@ -222,9 +223,14 @@ protected function getGlobals(\ReflectionClass $class)
222223
'methods' => array(),
223224
'host' => '',
224225
'condition' => '',
226+
'name' => '',
225227
);
226228

227229
if ($annot = $this->reader->getClassAnnotation($class, $this->routeAnnotationClass)) {
230+
if (null !== $annot->getName()) {
231+
$globals['name'] = $annot->getName();
232+
}
233+
228234
if (null !== $annot->getPath()) {
229235
$globals['path'] = $annot->getPath();
230236
}

‎src/Symfony/Component/Routing/Tests/Loader/AnnotationClassLoaderTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Tests/Loader/AnnotationClassLoaderTest.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ public function testLoad($className, $routeData = array(), $methodArgs = array()
149149
public function testClassRouteLoad()
150150
{
151151
$classRouteData = array(
152+
'name' => 'prefix_',
152153
'path' => '/prefix',
153154
'schemes' => array('https'),
154155
'methods' => array('GET'),
@@ -178,6 +179,7 @@ public function testClassRouteLoad()
178179
$this->assertSame($classRouteData['path'].$methodRouteData['path'], $route->getPath(), '->load concatenates class and method route path');
179180
$this->assertEquals(array_merge($classRouteData['schemes'], $methodRouteData['schemes']), $route->getSchemes(), '->load merges class and method route schemes');
180181
$this->assertEquals(array_merge($classRouteData['methods'], $methodRouteData['methods']), $route->getMethods(), '->load merges class and method route methods');
182+
$this->assertEquals('prefix_route1', $route->getName(), '->load prefixes route name with the main name');
181183
}
182184

183185
public function testInvokableClassRouteLoad()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.