
Events & Event Subscribers
EventDispatcher, event subscribers, listeners, kernel events, custom events, priorities
1What is the main role of the EventDispatcher component in Symfony?
What is the main role of the EventDispatcher component in Symfony?
Answer
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.
2What is the main difference between an Event Listener and an Event Subscriber in Symfony?
What is the main difference between an Event Listener and an Event Subscriber in Symfony?
Answer
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.
3How to declare an Event Subscriber in Symfony with the appropriate interface?
How to declare an Event Subscriber in Symfony with the appropriate interface?
Answer
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.
Which kernel event is triggered first when processing an HTTP request in Symfony?
How does the event priority system work in Symfony?
+17 interview questions
Other Symfony interview topics
Modern PHP (8.1+)
Symfony Basics
Routing & Controllers
Twig & Templates
Doctrine ORM Basics
Symfony Forms
Data Validation
Dependency Injection & Services
Security & Authentication
Doctrine Advanced
API Platform
Serializer Component
Console & Commands
Messenger Component
HTTP Client
Cache & Performance
Workflow Component
Testing Symfony
Mailer Component
Translations & i18n
EasyAdmin Bundle
Symfony Architecture
Performance & Optimization
Security Advanced
Custom Bundles
Microservices with Symfony
Real-time & WebSockets
Deployment & DevOps
Master Symfony for your next interview
Access all questions, flashcards, technical tests, code review exercises and interview simulators.
Start for free