8000 [HttpKernel] Don't bind scalar values to controller method arguments by yceruto · Pull Request #24600 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[HttpKernel] Don't bind scalar values to controller method arguments #24600

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

Merged
merged 1 commit into from
Oct 18, 2017

Conversation

yceruto
Copy link
Member
@yceruto yceruto commented Oct 18, 2017
Q A
Branch? 3.4
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #24555 (comment)
License MIT
Doc PR -

See linked issue.

Let's suppose we have this configuration:

services:
    _defaults:
        # ...
        bind:
            $foo: '%foobar%'

$foo was successfully bound to any controller constructor, but in another controller I have this edit action (nothing to do with the intention of bind such a parameter, but it has the same name):

/**
 * @Route("/{foo}/edit")
 */
public function editAction(string $foo) {}

triggering:

Type error: Argument 1 passed to Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument::__construct() must be an instance of Symfony\Component\DependencyInjection\Reference, string given, called in /home/yceruto/github/symfony/symfony-demo/vendor/symfony/dependency-injection/Compiler/ServiceLocatorTagPass.php on line 81

or after #24582:

Invalid service locator definition: only services can be referenced, "string" found for key "foo". Inject parameter values using constructors instead.

@fabpot
Copy link
Member
fabpot commented Oct 18, 2017

Thank you @yceruto.

@fabpot fabpot merged commit a1df9af into symfony:3.4 Oct 18, 2017
fabpot added a commit that referenced this pull request Oct 18, 2017
… arguments (yceruto)

This PR was merged into the 3.4 branch.

Discussion
----------

[HttpKernel] Don't bind scalar values to controller method arguments

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #24555 (comment)
| License       | MIT
| Doc PR        | -

See linked issue.

Let's suppose we have this configuration:
```yaml
services:
    _defaults:
        # ...
        bind:
            $foo: '%foobar%'
```
`$foo` was successfully bound to any controller constructor, but in another controller I have this edit action (nothing to do with the intention of bind such a parameter, but it has the same name):
```php
/**
 * @route("/{foo}/edit")
 */
public function editAction(string $foo) {}
```
triggering:
> Type error: Argument 1 passed to Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument::__construct() must be an instance of Symfony\Component\DependencyInjection\Reference, string given, called in /home/yceruto/github/symfony/symfony-demo/vendor/symfony/dependency-injection/Compiler/ServiceLocatorTagPass.php on line 81

or after #24582:
> Invalid service locator definition: only services can be referenced, "string" found for key "foo". Inject parameter values using constructors instead.

Commits
-------

a1df9af don't bind scalar values to controller method arguments
@yceruto yceruto deleted the bindings branch October 18, 2017 14:36
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.

7 participants
0