Skip to content

Commit e482da1

Browse files
committed
Merge branch '3.4' into 4.1
* 3.4: fix authorization checker variable name [Routing] Remove duplicate schemes and methods for invokable controllers [Bridge/PhpUnit] fix the fix
2 parents 9631c22 + 39d6228 commit e482da1

File tree

3 files changed

+22
-18
lines changed

3 files changed

+22
-18
lines changed

Loader/AnnotationClassLoader.php

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,9 @@ public function load($class, $type = null)
120120
}
121121

122122
if (0 === $collection->count() && $class->hasMethod('__invoke')) {
123+
$globals = $this->resetGlobals();
123124
foreach ($this->reader->getClassAnnotations($class) as $annot) {
124125
if ($annot instanceof $this->routeAnnotationClass) {
125-
$globals['path'] = '';
126-
$globals['name'] = '';
127-
$globals['localized_paths'] = array();
128-
129126
$this->addRoute($collection, $annot, $globals, $class, $class->getMethod('__invoke'));
130127
}
131128
}
@@ -254,18 +251,7 @@ protected function getDefaultRouteName(\ReflectionClass $class, \ReflectionMetho
254251

255252
protected function getGlobals(\ReflectionClass $class)
256253
{
257-
$globals = array(
258-
'path' => null,
259-
'localized_paths' => array(),
260-
'requirements' => array(),
261-
'options' => array(),
262-
'defaults' => array(),
263-
'schemes' => array(),
264-
'methods' => array(),
265-
'host' => '',
266-
'condition' => '',
267-
'name' => '',
268-
);
254+
$globals = $this->resetGlobals();
269255

270256
if ($annot = $this->reader->getClassAnnotation($class, $this->routeAnnotationClass)) {
271257
if (null !== $annot->getName()) {
@@ -310,6 +296,22 @@ protected function getGlobals(\ReflectionClass $class)
310296
return $globals;
311297
}
312298

299+
private function resetGlobals()
300+
{
301+
return array(
302+
'path' => null,
303+
'localized_paths' => array(),
304+
'requirements' => array(),
305+
'options' => array(),
306+
'defaults' => array(),
307+
'schemes' => array(),
308+
'methods' => array(),
309+
'host' => '',
310+
'condition' => '',
311+
'name' => '',
312+
);
313+
}
314+
313315
protected function createRoute($path, $defaults, $requirements, $options, $host, $schemes, $methods, $condition)
314316
{
315317
return new Route($path, $defaults, $requirements, $options, $host, $schemes, $methods, $condition);

Tests/Fixtures/AnnotationFixtures/InvokableController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Symfony\Component\Routing\Annotation\Route;
66

77
/**
8-
* @Route("/here", name="lol")
8+
* @Route("/here", name="lol", methods={"GET", "POST"}, schemes={"https"})
99
*/
1010
class InvokableController
1111
{

Tests/Loader/AnnotationClassLoaderTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ public function testInvokableControllerLoader()
9292
$routes = $this->loader->load(InvokableController::class);
9393
$this->assertCount(1, $routes);
9494
$this->assertEquals('/here', $routes->get('lol')->getPath());
95+
$this->assertEquals(array('GET', 'POST'), $routes->get('lol')->getMethods());
96+
$this->assertEquals(array('https'), $routes->get('lol')->getSchemes());
9597
}
9698

9799
public function testInvokableLocalizedControllerLoading()
@@ -134,7 +136,7 @@ public function testMethodActionControllers()
134136
$this->assertEquals('/the/path', $routes->get('post')->getPath());
135137
}
136138

137-
public function testLocalizedMethodActionControllers()
139+
public function testInvokableClassRouteLoadWithMethodAnnotation()
138140
{
139141
$routes = $this->loader->load(LocalizedMethodActionControllers::class);
140142
$this->assertCount(4, $routes);

0 commit comments

Comments
 (0)