-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[EventDispatcher] Add listener caller extension point #18873
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
Conversation
39a89a7
to
f09bdf9
Compare
I'm 👎 for this change as it makes the code complex at the Symfony level with more indirections and probably some small performance penalty. |
Technically, this PR doesn't allow to do something new. Symfony already provides the extension point (protected method). But existing extension point is painful in practice (as you can see, I have to extend
We can make some benchmarks, but I don't think it should be noticeable impact. |
*/ | ||
public function call(callable $listener, Event $event, $eventName, EventDispatcherInterface $eventDispatcher) | ||
{ | ||
$listener($event, $eventName, $eventDispatcher); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will not support all kind of callables (which is why the existing code still uses call_user_func
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's interesting. What kind of callables do you mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
array(__CLASS__, 'someStaticMethod')
cannot be called with this notation (this is the last remaining one in PHP 5.4+)
f09bdf9
to
a4d8626
Compare
I think this not something we need in Symfony. Your use case is very specific and I'm not willing to add this extension point as it is not useful for regular usages of the component. |
I found another case for this extension point: it makes sense to catch exceptions from listeners and log them. In case of "true" events, we don't really care about listeners from caller perspective. For example, in our system, we managed to enqueue some listeners in order to execute them later (in shutdown callback). Thus, listeners may be executed in indefinite time point and throwing exceptions from them is something similar to throwing exceptions from It is possible to fix it by inheritance, but again I don't find this solution perfect. |
In our project we reuse infrastructure of the EventDispatcher for dispatching domain events. In the past we had 2 issues:
Event
class (because it makes our domain coupled on the framework and it also contains undesirablepropagation
logic);eventName
, i.e. our "event name" is simpleget_class($event)
.We introduced
DomainEventEnvelope extends \Symfony\Component\EventDispatcher\Event
and the following dispatcher:It works, but this solution is rather bad. This PR adds new extension point in the
EventDispatcher
which allows to solve issue above with composition: