8000 Merge branch '3.4' · symfony/routing@a2193cc · GitHub
[go: up one dir, main page]

Skip to content

Commit a2193cc

Browse files
Merge branch '3.4'
* 3.4: Improved the design of the redirection method in the web toolbar Mark SemaphoreStore::isSupported() as internal [DI] Add ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE [FrameworkBundle] Fix form conflict rule [Security] add impersonator_user to "User was reloaded" log message [DI] Add upgrade note about case insenstive params add (pdo|chain) cache (adapter|simple) prune method Update NoSuchPropertyException message for writeProperty [Routing] added the possibility to define a prefix for all routes of a controller [DI] Don't track merged configs when the extension doesn't expose it [Cache] Use namespace versioning for backends that dont support clearing by keys [VarDumper] add force-collapse/expand + use it for traces
2 parents 2c80ec4 + a7dbe78 commit a2193cc

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ CHANGELOG
1010
3.4.0
1111
-----
1212

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

Loader/AnnotationClassLoader.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ public function load($class, $type = null)
129129

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

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

145147
$defaults = array_replace($globals['defaults'], $annot->getDefaults());
146148
foreach ($method->getParameters() as $param) {
@@ -222,9 +224,14 @@ protected function getGlobals(\ReflectionClass $class)
222224
'methods' => array(),
223225
'host' => '',
224226
'condition' => '',
227+
'name' => '',
225228
);
226229

227230
if ($annot = $this->reader->getClassAnnotation($class, $this->routeAnnotationClass)) {
231+
if (null !== $annot->getName()) {
232+
$globals['name'] = $annot->getName();
233+
}
234+
228235
if (null !== $annot->getPath()) {
229236
$globals['path'] = $annot->getPath();
230237
}

Tests/Loader/AnnotationClassLoaderTest.php

Lines changed: 3 additions & 2 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'),
@@ -173,7 +174,7 @@ public function testClassRouteLoad()
173174
;
174175

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

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');
@@ -240,7 +241,7 @@ public function testInvokableClassWithMethodRouteLoad()
240241

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

243-
$route = $routeCollection->get($methodRouteData['name']);
244+
$route = $routeCollection->get($classRouteData['name'].$methodRouteData['name']);
244245

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

0 commit comments

Comments
 (0)
0