Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[DependencyInjection] don't move locator tag for service subscriber#48093

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

@RobertMe
Copy link
Contributor

QA
Branch?4.4
Bug fix?yes
New feature?no
Deprecations?no
Tickets-
LicenseMIT
Doc PR-

From the commit message:
Decorators move tags applied to the decorated service to the decorating service. But this (sometimes) breaks when the decorated service is a service subscriber, which has the argument for the container explicitly set.

This mostly works because the locator for the service subscriber is applied twice. The RegisterServiceSubscriberPass which creates the locator also sets a binding on the service. The
ResolveServiceSubscriberPass replaces the arguments referencing the ContainerInterface or ServiceProviderInterface for those services tagged with the container.service_subscriber.locator tag. So when the argument isn't provided in the service definition it will automatically be set using the binding. And in case the argument is set, it will be replaced by the Resolver pass based on the tag.

But this thus breaks in case a service explicitly sets the argument (which means the binding isn't applied) and the service being decorated (meaning the locator tag is "lost"). So add the locator tag to the list of tags to keep on the original service.

Explanation:
I found this issue when decorating theRouter. TheRouter (inFrameworkBundle) uses a service subscriber, but this lead to a deprecation message for autowiringPsr\...\ContainerInterface. Debugging also showed that the full container was injected, and not the extracted service locator (service locator service actually was logged as removed for being unused). After investigation the issue was found to be as described above. Therouter service is declared with an argument for the$container parameter of the constructor, i.e.:

<serviceid="router.default"class="Symfony\Bundle\FrameworkBundle\Routing\Router">            <argumenttype="service"id="Psr\Container\ContainerInterface" />

Which leads to the binding, as declared in theRegisterServiceSubscribersPass pass not being applied. Later on theDecoratorServicePass pass moves the tags of the decorated service to the decorating service, where it only keeps thecontainer.service_subscriber tag on the original service, and moves thecontainer.service_subscriber.locator tag to the decorating service. When afterwards theResolveServiceSubscribersPass pass is executed it will replace the arguments to theContainerInterface with the created locator service (as defined in theRegisterServiceSubscribersPass). But this then fails because thecontainer.service_subscriber.locator tag isn't applied anymore.

So when therouter isn't decorated theResolveServiceSubscribersPass pass is the one which makes the service subscriber work, replacing the original argument as defined in the service definition. But when it is decorated this breaks because the tag is missing.
The unit tests didn't detect this because: 1. the container isn't injected (and thus not validated); 2. even with validation of the container it would work as the binding would be applied. This is why I also kept the original unit test (but expanding the test with validating the container), which would still pass (based on the binding), and adding the additional test which explicitly sets the$container argument, which would fail (for the binding not being applied, and the tag being missing because of the decorator).

Decorators move tags applied to the decorated service to the decoratingservice. But this (sometimes) breaks when the decorated service is aservice subscriber, which has the argument for the container explicitlyset.This mostly works because the locator for the service subscriber isapplied twice. The RegisterServiceSubscriberPass which creates thelocator also sets a binding on the service. TheResolveServiceSubscriberPass replaces the arguments referencing theContainerInterface or ServiceProviderInterface for those services taggedwith the container.service_subscriber.locator tag. So when the argumentisn't provided in the service definition it will automatically be setusing the binding. And in case the argument is set, it will be replacedby the Resolver pass based on the tag.But this thus breaks in case a service explicitly sets theargument (which means the binding isn't applied) and the service beingdecorated (meaning the locator tag is "lost"). So add the locator tagto the list of tags to keep on the original service.
@RobertMeRobertMeforce-pushed thereplace-container-of-decorated-service-subscriber-with-argument branch fromc4b0e31 to3c7dbb4CompareNovember 3, 2022 17:29
@nicolas-grekas
Copy link
Member

Thank you@RobertMe.

RobertMe reacted with thumbs up emoji

@nicolas-grekasnicolas-grekas merged commitad0e25f intosymfony:4.4Nov 4, 2022
@RobertMeRobertMe deleted the replace-container-of-decorated-service-subscriber-with-argument branchNovember 4, 2022 08:08
@fabpotfabpot mentioned this pull requestNov 19, 2022
This was referencedNov 28, 2022
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Projects

None yet

Milestone

4.4

Development

Successfully merging this pull request may close these issues.

3 participants

@RobertMe@nicolas-grekas@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp