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

Skip to content

[HttpKernel] Fix services are no longer injected into __invoke controllers method #27214

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
May 14, 2018
Merged

[HttpKernel] Fix services are no longer injected into __invoke controllers method #27214

merged 1 commit into from
May 14, 2018

Conversation

ogizanagi
Copy link
Contributor

@ogizanagi ogizanagi commented May 9, 2018

Q A
Branch? 4.1
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #27208
License MIT
Doc PR N/A

TL;DR: The RemoveEmptyControllerArgumentLocatorsPass is the one adding the Controller::_invoke => Controller shortcut missing from the service locator. It isn't properly executed on some cases. This fixes it.

Since #26833, the resolvers are decorated by a TraceableValueResolver, which usually isn't much an issue to deal within passes. But the RemoveEmptyControllerArgumentLocatorsPass happens late (TYPE_BEFORE_REMOVING), when decoration inheritance is already resolved, so accessing $controllerLocator = $container->getDefinition((string) $serviceResolver->getArgument(0)); isn't accessing the controller locator, but the decorated service instead.

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(with minor comment, maybe add a test if worth it?)

->replaceArgument(0, ServiceLocatorTagPass::register($container, $controllers));
->replaceArgument(0, $controllerLocatorRef = ServiceLocatorTagPass::register($container, $controllers));

$container->setAlias($this->controllerLocator, (string) $controllerLocatorRef)->setPrivate(true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Being private is already the default, isn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, indeed.

@ogizanagi
Copy link
Contributor Author

ogizanagi commented May 10, 2018

Not sure which kind of tests would be really relevant here, nor if it is worth the hassle :)

@lunetics
Copy link

+1, just ran into that issue too after updating to 4.1 beta

@fabpot
Copy link
Member

fabpot commented May 14, 2018

Thank you @ogizanagi.

@fabpot fabpot merged commit ee44903 into symfony:4.1 May 14, 2018
fabpot added a commit that referenced this pull request May 14, 2018
…voke controllers method (ogizanagi)

This PR was merged into the 4.1 branch.

Discussion
----------

[HttpKernel] Fix services are no longer injected into __invoke controllers method

| Q             | A
| ------------- | ---
| Branch?       | 4.1 <!-- see below -->
| Bug fix?      | yes
| New feature?  | no <!-- don't forget to update src/**/CHANGELOG.md files -->
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | #27208   <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        | N/A

_TL;DR:_ The `RemoveEmptyControllerArgumentLocatorsPass` is the one adding the `Controller::_invoke` => `Controller` shortcut missing from the service locator. It isn't properly executed on some cases. This fixes it.

Since #26833, the resolvers are decorated by a `TraceableValueResolver`, which usually isn't much an issue to deal within passes. But the `RemoveEmptyControllerArgumentLocatorsPass` happens late (`TYPE_BEFORE_REMOVING`), when decoration inheritance is already resolved, so accessing `$controllerLocator = $container->getDefinition((string) $serviceResolver->getArgument(0));` isn't accessing the controller locator, but the decorated service instead.

Commits
-------

ee44903 [HttpKernel] Fix services are no longer injected into __invoke controllers method
@ogizanagi ogizanagi deleted the fix/service_arg_invokable_controller branch May 14, 2018 07:01
@fabpot fabpot mentioned this pull request May 21, 2018
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.

5 participants