[Routing] Remove duplicate schemes and methods for invokable controllers
This commit is contained in:
parent
b6f9f8d769
commit
640ccdf069
@ -120,11 +120,9 @@ abstract class AnnotationClassLoader implements LoaderInterface
|
||||
}
|
||||
|
||||
if (0 === $collection->count() && $class->hasMethod('__invoke')) {
|
||||
$globals = $this->resetGlobals();
|
||||
foreach ($this->reader->getClassAnnotations($class) as $annot) {
|
||||
if ($annot instanceof $this->routeAnnotationClass) {
|
||||
$globals['path'] = '';
|
||||
$globals['name'] = '';
|
||||
|
||||
$this->addRoute($collection, $annot, $globals, $class, $class->getMethod('__invoke'));
|
||||
}
|
||||
}
|
||||
@ -212,17 +210,7 @@ abstract class AnnotationClassLoader implements LoaderInterface
|
||||
|
||||
protected function getGlobals(\ReflectionClass $class)
|
||||
{
|
||||
$globals = array(
|
||||
'path' => '',
|
||||
'requirements' => array(),
|
||||
'options' => array(),
|
||||
'defaults' => array(),
|
||||
'schemes' => array(),
|
||||
'methods' => array(),
|
||||
'host' => '',
|
||||
'condition' => '',
|
||||
'name' => '',
|
||||
);
|
||||
$globals = $this->resetGlobals();
|
||||
|
||||
if ($annot = $this->reader->getClassAnnotation($class, $this->routeAnnotationClass)) {
|
||||
if (null !== $annot->getName()) {
|
||||
@ -265,6 +253,21 @@ abstract class AnnotationClassLoader implements LoaderInterface
|
||||
return $globals;
|
||||
}
|
||||
|
||||
private function resetGlobals()
|
||||
{
|
||||
return array(
|
||||
'path' => '',
|
||||
'requirements' => array(),
|
||||
'options' => array(),
|
||||
'defaults' => array(),
|
||||
'schemes' => array(),
|
||||
'methods' => array(),
|
||||
'host' => '',
|
||||
'condition' => '',
|
||||
'name' => '',
|
||||
);
|
||||
}
|
||||
|
||||
protected function createRoute($path, $defaults, $requirements, $options, $host, $schemes, $methods, $condition)
|
||||
{
|
||||
return new Route($path, $defaults, $requirements, $options, $host, $schemes, $methods, $condition);
|
||||
|
@ -181,7 +181,7 @@ class AnnotationClassLoaderTest extends AbstractAnnotationLoaderTest
|
||||
$this->assertEquals(array_merge($classRouteData['methods'], $methodRouteData['methods']), $route->getMethods(), '->load merges class and method route methods');
|
||||
}
|
||||
|
||||
public function testInvokableClassRouteLoad()
|
||||
public function testInvokableClassRouteLoadWithMethodAnnotation()
|
||||
{
|
||||
$classRouteData = array(
|
||||
'name' => 'route1',
|
||||
@ -209,6 +209,41 @@ class AnnotationClassLoaderTest extends AbstractAnnotationLoaderTest
|
||||
$this->assertEquals($classRouteData['methods'], $route->getMethods(), '->load preserves class route methods');
|
||||
}
|
||||
|
||||
public function testInvokableClassRouteLoadWithClassAnnotation()
|
||||
{
|
||||
$classRouteData = array(
|
||||
'name' => 'route1',
|
||||
'path' => '/',
|
||||
'schemes' => array('https'),
|
||||
'methods' => array('GET'),
|
||||
);
|
||||
|
||||
$this->reader
|
||||
->expects($this->exactly(1))
|
||||
->method('getClassAnnotation')
|
||||
->will($this->returnValue($this->getAnnotatedRoute($classRouteData)))
|
||||
;
|
||||
|
||||
$this->reader
|
||||
->expects($this->exactly(1))
|
||||
->method('getClassAnnotations')
|
||||
->will($this->returnValue(array($this->getAnnotatedRoute($classRouteData))))
|
||||
;
|
||||
|
||||
$this->reader
|
||||
->expects($this->once())
|
||||
->method('getMethodAnnotations')
|
||||
->will($this->returnValue(array()))
|
||||
;
|
||||
|
||||
$routeCollection = $this->loader->load('Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BazClass');
|
||||
$route = $routeCollection->get($classRouteData['name']);
|
||||
|
||||
$this->assertSame($classRouteData['path'], $route->getPath(), '->load preserves class route path');
|
||||
$this->assertEquals($classRouteData['schemes'], $route->getSchemes(), '->load preserves class route schemes');
|
||||
$this->assertEquals($classRouteData['methods'], $route->getMethods(), '->load preserves class route methods');
|
||||
}
|
||||
|
||||
public function testInvokableClassMultipleRouteLoad()
|
||||
{
|
||||
$classRouteData1 = array(
|
||||
|
Reference in New Issue
Block a user