Answer the question
In order to leave comments, you need to log in
What is the difference between EventListener and Subscriber in Symfony2?
1. What is the difference between EventListener and Subscriber in Symfony2?
2. What is the subscriber for and where to use it?
3. Why call EventDispather? Isn't it enough to define a listener and an event ?
Answer the question
In order to leave comments, you need to log in
1. The only difference is that Subscriber defines several listeners at once.
2. Using Subscriber, it is convenient to subscribe to several events of the same class at once. For example, Doctrine - you can immediately subscribe to postPersist and postUpdate and register one Subscriber. If you do the same through the Listener, then you will have to create your own Listener for each event and register it separately.
3. If you have registered the Listener/Subscriber through the Service Container, then you do not need to call the EventDispatcher. If you want to subscribe to events at runtime, then yes, you will have to call EventDispatcher.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question