Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[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

Closed
wants to merge 1 commit into from
Closed

[HttpKernel] Allow variadic controller parameters to be resolved. #15777

wants to merge 1 commit into from

Conversation

akerouanton
Copy link

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.

@@ -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])) {
Copy link
Member

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.

@stof
Copy link
Member

stof commented Sep 16, 2015

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));
Copy link
Contributor

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 ;)

@fabpot
Copy link
Member

fabpot commented Oct 19, 2015

@NiR- Can you have a look at the comments and finish this PR?

@fabpot
Copy link
Member

fabpot commented Jan 25, 2016

@NiR- Any news?

@fabpot
Copy link
Member

fabpot commented Mar 1, 2016

#17971

@fabpot fabpot closed this Mar 1, 2016
fabpot added a commit that referenced this pull request Mar 1, 2016
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants