-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DependencyInjection] Decorating event listeners #19697
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
Comments
The issue IMO is the order of compiler passes: registering listeners should be done before resolving service decoration, so that the decorated service is registered as a listener with its original id (and so the decorator service will then be used when calling the listener) instead of registering it with its internal generated id (which would not call the decorator service, even if we keep it public to allow lazy-loading). @symfony/deciders I suggest that the resolution of service decoration is kept as late as possible, so that all compiler passes collecting services based on their tags are applied before that, so that they collect the original id (and so take service decoration into account). This would mean making it run at the very end of the "before optimization" passes, even after passes added by other bundles (which can be achieved in 3.2 as we added a concept of priorities). What do you think about that ? |
Sounds like a reasonable solution. This will also solve the use cases where you had to duplicate tag definitions from the decorated service. |
@teohhanhui Any version including the fix from #20207 shouldn't suffer from the limitation you pointed out anymore. However, we may want to think about whether there are still other advantages of changing the order in which the compiler passes are executed. |
Shall we close this one? |
Currently, decorating event listeners (
kernel.event_listener
) makes the decorated service private:https://github.com/symfony/dependency-injection/blob/5d4f4ff02a3a5b24a7c81bb7e22f2e57c7526ee2/Compiler/DecoratorServicePass.php#L47-L58
resulting in an exception being thrown here:
symfony/src/Symfony/Component/EventDispatcher/DependencyInjection/RegisterListenersPass.php
Lines 61 to 63 in 94078a0
This makes it impossible to decorate event listeners. (Also, I can't find any tests of decorating event listeners. Are there any?)
The text was updated successfully, but these errors were encountered: