merged branch stloyd/bugfix/issue-7724 (PR #8393)
This PR was merged into the 2.2 branch.
Discussion
----------
[2.2] Return BC compatibility for `@Route` parameters and default values
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #7724
| License | MIT
Commits
-------
d400b5a
Return BC compatibility for `@Route` parameters and default values
This commit is contained in:
commit
567e3f4642
@ -180,7 +180,7 @@ abstract class AnnotationClassLoader implements LoaderInterface
|
|||||||
|
|
||||||
$defaults = array_replace($globals['defaults'], $annot->getDefaults());
|
$defaults = array_replace($globals['defaults'], $annot->getDefaults());
|
||||||
foreach ($method->getParameters() as $param) {
|
foreach ($method->getParameters() as $param) {
|
||||||
if ($param->isOptional()) {
|
if (!isset($defaults[$param->getName()]) && $param->isOptional()) {
|
||||||
$defaults[$param->getName()] = $param->getDefaultValue();
|
$defaults[$param->getName()] = $param->getDefaultValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Routing\Tests\Loader;
|
namespace Symfony\Component\Routing\Tests\Loader;
|
||||||
|
|
||||||
|
use Symfony\Component\Routing\Annotation\Route;
|
||||||
|
|
||||||
class AnnotationClassLoaderTest extends AbstractAnnotationLoaderTest
|
class AnnotationClassLoaderTest extends AbstractAnnotationLoaderTest
|
||||||
{
|
{
|
||||||
protected $loader;
|
protected $loader;
|
||||||
@ -79,6 +81,11 @@ class AnnotationClassLoaderTest extends AbstractAnnotationLoaderTest
|
|||||||
array('name' => 'route1', 'defaults' => array('arg2' => 'foo')),
|
array('name' => 'route1', 'defaults' => array('arg2' => 'foo')),
|
||||||
array('arg2' => 'defaultValue2', 'arg3' => 'defaultValue3')
|
array('arg2' => 'defaultValue2', 'arg3' => 'defaultValue3')
|
||||||
),
|
),
|
||||||
|
array(
|
||||||
|
'Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BarClass',
|
||||||
|
array('name' => 'route1', 'defaults' => array('arg2' => 'foobar')),
|
||||||
|
array('arg2' => false, 'arg3' => 'defaultValue3')
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,12 +115,11 @@ class AnnotationClassLoaderTest extends AbstractAnnotationLoaderTest
|
|||||||
$this->assertSame($routeDatas['path'], $route->getPath(), '->load preserves path annotation');
|
$this->assertSame($routeDatas['path'], $route->getPath(), '->load preserves path annotation');
|
||||||
$this->assertSame($routeDatas['requirements'],$route->getRequirements(), '->load preserves requirements annotation');
|
$this->assertSame($routeDatas['requirements'],$route->getRequirements(), '->load preserves requirements annotation');
|
||||||
$this->assertCount(0, array_intersect($route->getOptions(), $routeDatas['options']), '->load preserves options annotation');
|
$this->assertCount(0, array_intersect($route->getOptions(), $routeDatas['options']), '->load preserves options annotation');
|
||||||
$this->assertSame(array_replace($routeDatas['defaults'], $methodArgs), $route->getDefaults(), '->load preserves defaults annotation');
|
$this->assertSame(array_replace($methodArgs, $routeDatas['defaults']), $route->getDefaults(), '->load preserves defaults annotation');
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getAnnotatedRoute($datas)
|
private function getAnnotatedRoute($datas)
|
||||||
{
|
{
|
||||||
return new \Symfony\Component\Routing\Annotation\Route($datas);
|
return new Route($datas);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user