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

Skip to content

[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

Closed
teohhanhui opened this issue Aug 22, 2016 · 5 comments
Closed

[DependencyInjection] Decorating event listeners #19697

teohhanhui opened this issue Aug 22, 2016 · 5 comments

Comments

@teohhanhui
Copy link
Contributor

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:

if (!$def->isPublic()) {
throw new \InvalidArgumentException(sprintf('The service "%s" must be public as event listeners are lazy-loaded.', $id));
}

This makes it impossible to decorate event listeners. (Also, I can't find any tests of decorating event listeners. Are there any?)

@stof
Copy link
Member

stof commented Aug 22, 2016

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 ?

@xabbuh
Copy link
Member

xabbuh commented Aug 23, 2016

Sounds like a reasonable solution. This will also solve the use cases where you had to duplicate tag definitions from the decorated service.

@teohhanhui
Copy link
Contributor Author

@xabbuh Does #20207 change anything about this issue?

@xabbuh
Copy link
Member

xabbuh commented Nov 8, 2016

@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.

@nicolas-grekas
Copy link
Member

Shall we close this one?

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

4 participants