Symfony

Events & Event Subscribers

EventDispatcher, event subscribers, listeners, kernel events, custom events, priorities

20 preguntas de entrevista·
Mid-Level
1

What is the main role of the EventDispatcher component in Symfony?

Respuesta

The EventDispatcher component implements the Observer pattern and allows decoupling different parts of an application. It centralizes event management by enabling listeners to react to dispatched events without components knowing each other directly. This promotes a modular and extensible architecture where new features can be added without modifying existing code.

2

What is the main difference between an Event Listener and an Event Subscriber in Symfony?

Respuesta

An Event Subscriber implements EventSubscriberInterface and defines listened events via the static getSubscribedEvents() method. A Listener is a class or callable configured via services.yaml or the #[AsEventListener] attribute. Subscribers are self-descriptive and more portable, while Listeners offer more flexibility in external configuration.

3

How to declare an Event Subscriber in Symfony with the appropriate interface?

Respuesta

An Event Subscriber must implement EventSubscriberInterface and define the static getSubscribedEvents() method returning an associative array. Keys are event names and values can be the method name, an array with method and priority, or an array of arrays for multiple methods on the same event.

4

Which kernel event is triggered first when processing an HTTP request in Symfony?

5

How does the event priority system work in Symfony?

+17 preguntas de entrevista

Domina Symfony para tu próxima entrevista

Accede a todas las preguntas, flashcards, tests técnicos, ejercicios de code review y simuladores de entrevista.

Empieza gratis