-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Closed
Labels
EventDispatcheractionableClear and specific issues ready for anyone to take them.Clear and specific issues ready for anyone to take them.good first issueIdeal for your first contribution! (some Symfony experience may be required)Ideal for your first contribution! (some Symfony experience may be required)
Description
Might be worth adding one note why should one choose event listener over subscriber and vice versa. As far as I know they act essentially the same if configured properly. For example an event subscriber is aware of subscribed events by implementing EventSubscriberInterface::getSubscribedEvents()
. But event listeners can also listen on several events simply by adding more tags:
<service id="awesome_listener" class="Super\AwesomeListener">
<tag name="kernel.event_listener" event="kernel.view" method="onKernelView" priority="1" />
<tag name="kernel.event_listener" event="kernel.view" method="onKernelView" priority="2" />
<tag name="kernel.event_listener" event="kernel.view" method="onKernelView" priority="3" />
<tag name="kernel.event_listener" event="kernel.view" method="onKernelView" priority="4" />
<!-- Any event type, handler method, as much as you want... -->
</service>
Also it might be a good idea to uniquely distinguish them all with Listener
suffix (talking about class name). People seem to be confused what listener is and what is subscriber and they usually do things like ProfilerListener
but also RequestSubscriber
in their own code. And they say that is in official documentation which is true (look for StoreSubscriber
) :)
Thanks!
dmecke and ersin-demirtas
Metadata
Metadata
Assignees
Labels
EventDispatcheractionableClear and specific issues ready for anyone to take them.Clear and specific issues ready for anyone to take them.good first issueIdeal for your first contribution! (some Symfony experience may be required)Ideal for your first contribution! (some Symfony experience may be required)