[Routing] Fix: annotation loader ignores method's default values
This commit is contained in:
parent
a362b8b838
commit
9b37793cbe
@ -196,7 +196,7 @@ abstract class AnnotationClassLoader implements LoaderInterface
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
foreach ($paths as $locale => $path) {
|
foreach ($paths as $locale => $path) {
|
||||||
if (false !== strpos($path, sprintf('{%s}', $param->name))) {
|
if (preg_match(sprintf('/\{%s(?:<.*?>)?\}/', preg_quote($param->name)), $path)) {
|
||||||
$defaults[$param->name] = $param->getDefaultValue();
|
$defaults[$param->name] = $param->getDefaultValue();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -12,4 +12,12 @@ class DefaultValueController
|
|||||||
public function action($default = 'value')
|
public function action($default = 'value')
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Route("/hello/{name<\w+>}", name="hello_without_default")
|
||||||
|
* @Route("/hello/{name<\w+>?Symfony}", name="hello_with_default")
|
||||||
|
*/
|
||||||
|
public function hello(string $name = 'World')
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -136,9 +136,11 @@ class AnnotationClassLoaderTest extends AbstractAnnotationLoaderTest
|
|||||||
public function testDefaultValuesForMethods()
|
public function testDefaultValuesForMethods()
|
||||||
{
|
{
|
||||||
$routes = $this->loader->load(DefaultValueController::class);
|
$routes = $this->loader->load(DefaultValueController::class);
|
||||||
$this->assertCount(1, $routes);
|
$this->assertCount(3, $routes);
|
||||||
$this->assertEquals('/{default}/path', $routes->get('action')->getPath());
|
$this->assertEquals('/{default}/path', $routes->get('action')->getPath());
|
||||||
$this->assertEquals('value', $routes->get('action')->getDefault('default'));
|
$this->assertEquals('value', $routes->get('action')->getDefault('default'));
|
||||||
|
$this->assertEquals('Symfony', $routes->get('hello_with_default')->getDefault('name'));
|
||||||
|
$this->assertEquals('World', $routes->get('hello_without_default')->getDefault('name'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMethodActionControllers()
|
public function testMethodActionControllers()
|
||||||
|
Reference in New Issue
Block a user