Skip to content
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

[Autowiring] Controller/Actions are not autowired if called through twig render*( #35909

Closed
Plopix opened this issue Feb 29, 2020 · 6 comments
Closed

Comments

@Plopix
Copy link
Contributor

Plopix commented Feb 29, 2020

Symfony version(s) affected: 5.0
(it works on 4.4)

Description
Autowiring is correctly set up and it is working as expected but not when using render functions.
https://github.com/Plopix/symfony-autowiring-render-twig-bug/blob/master/sf5/src/Controller/DefaultController.php

OK in SF 4.4, not on SF 5.0

How to reproduce
Here is a reproducer.
https://github.com/Plopix/symfony-autowiring-render-twig-bug

just checkout

cd sf4
composer install
symfony server:start
cd sf5
composer install
symfony server:start

but you'd know that ;)

@noemi-salaun
Copy link
Contributor

You issue come from your controller syntax App\Controller\DefaultController:embed. It should be App\Controller\DefaultController::embed. Note the double colon.

Since SF 4.1 the first notation is deprecated.
See https://github.com/symfony/symfony/blob/master/UPGRADE-4.1.md#frameworkbundle

The change takes place in \Symfony\Component\HttpKernel\DependencyInjection\RemoveEmptyControllerArgumentLocatorsPass.

SF 4.4

                if (!$reason) {
                    // Deprecated since Symfony 4.1. See Symfony\Component\HttpKernel\Controller\ContainerControllerResolver
                    $controllers[$id.':'.$action] = $argumentRef;

                    if ('__invoke' === $action) {
                        $controllers[$id] = $argumentRef;
                    }
                    continue;
                }

SF 5.0

                if (!$reason) {
                    if ('__invoke' === $action) {
                        $controllers[$id] = $argumentRef;
                    }
                    continue;
                }

And easier reproductible case was just defining a route in yaml

index:
    path: /
    controller: App\Controller\DefaultController:index    # <--- with 1 colon

I take a look at the deprecation logs, but using the wrong syntax in 4.4 does not trigger any deprecation :/

noemi-salaun added a commit to noemi-salaun/symfony that referenced this issue Mar 9, 2020
…lueResolver

Single colon syntax when referencing a controller as a service
is deprecated since Symfony 4.1 but there was no deprecations
trigger on runtime.

See symfony#35909
noemi-salaun added a commit to noemi-salaun/symfony that referenced this issue Mar 9, 2020
…alueResolver

Single colon syntax when referencing a controller as a service
is deprecated since Symfony 4.1 but there was no deprecations
trigger on runtime.

See symfony#35909
@Plopix
Copy link
Contributor Author

Plopix commented Mar 10, 2020

Nice @noemi-salaun! Indeed! it is not a bug then...That is interesting the syntax with : is still working!

@nicolas-grekas
Copy link
Member

Shall we close then?

@Plopix
Copy link
Contributor Author

Plopix commented Mar 10, 2020

I guess so. I mean 4.1 is a long time ago. If it's happening to someone they may find this closed issue for help.

noemi-salaun added a commit to noemi-salaun/symfony that referenced this issue Mar 10, 2020
…alueResolver

Single colon syntax when referencing a controller as a service
is deprecated since Symfony 4.1 but there was no deprecations
trigger on runtime.

See symfony#35909
@nicolas-grekas
Copy link
Member

Fixed in #36017 actually.

@noemi-salaun
Copy link
Contributor

@nicolas-grekas you can close my PR #36010 then. I didn't know if it was a bug in v5.0 or a missing deprecation in v4.1+. But apparently it was a bug ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants