-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[HttpKernel] Allow variadic controller parameters to be resolved. #15777
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -125,7 +125,11 @@ protected function doGetArguments(Request $request, $controller, array $paramete | |||
$arguments = array(); | |||
foreach ($parameters as $param) { | |||
if (array_key_exists($param->name, $attributes)) { | |||
$arguments[] = $attributes[$param->name]; | |||
if ($param->isVariadic() && is_array($attributes[$param->name])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you first have to check if this method exists, as Symfony should also support PHP 5.3, 5.4 and 5.5.
you also need to handle the case of a variadic parameter not being passed, to avoid throwing an exception in such case (see how it is done in https://github.com/symfony/symfony/pull/15426/files for the serializer) |
| Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a Variadic parameters in controller signature were not handled correctly by the `ControllerResolver`.
$request->attributes->set('foo', 'foo'); | ||
$request->attributes->set('bar', array($param1, $param2)); | ||
$controller = array(new VariadicController(), 'action'); | ||
$this->assertEquals(array('foo', $param1, $param2), $resolver->getArguments($request, $controller)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be assertSame()
as assertEquals()
would not make a distinction between ['foo', $param1, $param2]
and ['foo', $param1, $param1]
.
Also, consider using strings instead of stdClass
here. In this case type doesn't matter and if we can make the test shorter, we should ;)
@NiR- Can you have a look at the comments and finish this PR? |
@NiR- Any news? |
This PR was merged into the 2.3 branch. Discussion ---------- Variadic controller params | Q | A | ------------- | --- | Branch | 2.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #15777 | License | MIT Commits ------- bedcb15 simplified code f39afc8 Allow variadic controller parameters to be resolved.
Variadic parameters in controller signature were not handled correctly by the
ControllerResolver
.