Event Dispatcher Flashcards
What OOP patterns does the event-dispatcher component implement?
Mediator and observer
What methods does Symfony\Component\EventDispatcher\EventDispatcherInterface define?
addListener(string $eventName, $listener, int $priority = 0);
addSubscriber(EventSubscriberInterface $subscriber);
removeListener(string $eventName, $listener);
removeSubscriber(EventSubscriberInterface $subscriber);
getListeners(string $eventName = null);
getListenerPriority(string $eventName, $listener);
hasListeners(string $eventName = null);
What tags are used to register event listeners and event subscribers via the DIC?
kernel. event_listener
kernel. event_subscriber
What is the difference between an event listener and event subscriber?
Event listener is a PHP callable that is triggered when a specific event is fired. Event subscriber is a class that implements Symfony\Component\EventDispatcher\EventSubscriberInterface and defines any number of possible methods to be triggered by any number of possible events.