simplified code
This commit is contained in:
parent
f39afc85db
commit
bedcb151b8
@ -117,10 +117,9 @@ class ControllerResolver implements ControllerResolverInterface
|
|||||||
{
|
{
|
||||||
$attributes = $request->attributes->all();
|
$attributes = $request->attributes->all();
|
||||||
$arguments = array();
|
$arguments = array();
|
||||||
$variadicAvailable = method_exists('\ReflectionMethod', 'isVariadic');
|
|
||||||
foreach ($parameters as $param) {
|
foreach ($parameters as $param) {
|
||||||
if (array_key_exists($param->name, $attributes)) {
|
if (array_key_exists($param->name, $attributes)) {
|
||||||
if ($variadicAvailable && $param->isVariadic() && is_array($attributes[$param->name])) {
|
if (PHP_VERSION_ID >= 50600 && $param->isVariadic() && is_array($attributes[$param->name])) {
|
||||||
$arguments = array_merge($arguments, array_values($attributes[$param->name]));
|
$arguments = array_merge($arguments, array_values($attributes[$param->name]));
|
||||||
} else {
|
} else {
|
||||||
$arguments[] = $attributes[$param->name];
|
$arguments[] = $attributes[$param->name];
|
||||||
|
@ -205,12 +205,10 @@ class ControllerResolverTest extends \PHPUnit_Framework_TestCase
|
|||||||
$resolver = new ControllerResolver();
|
$resolver = new ControllerResolver();
|
||||||
|
|
||||||
$request = Request::create('/');
|
$request = Request::create('/');
|
||||||
$param1 = new \stdClass();
|
|
||||||
$param2 = new \stdClass();
|
|
||||||
$request->attributes->set('foo', 'foo');
|
$request->attributes->set('foo', 'foo');
|
||||||
$request->attributes->set('bar', array($param1, $param2));
|
$request->attributes->set('bar', array('foo', 'bar'));
|
||||||
$controller = array(new VariadicController(), 'action');
|
$controller = array(new VariadicController(), 'action');
|
||||||
$this->assertEquals(array('foo', $param1, $param2), $resolver->getArguments($request, $controller));
|
$this->assertEquals(array('foo', 'foo', 'bar'), $resolver->getArguments($request, $controller));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCreateControllerCanReturnAnyCallable()
|
public function testCreateControllerCanReturnAnyCallable()
|
||||||
|
@ -4,7 +4,7 @@ namespace Symfony\Component\HttpKernel\Tests\Fixtures\Controller;
|
|||||||
|
|
||||||
class VariadicController
|
class VariadicController
|
||||||
{
|
{
|
||||||
public function action($foo,...$bar)
|
public function action($foo, ...$bar)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user