Documentation
README
Doctrine Events (Symfony)
Use when
- You need side effects on entity persistence (timestamps, slugs, search indexing, notifications).
- Migrating an
EventSubscriberInterfaceDoctrine subscriber to ORM 3. - Choosing between lifecycle callbacks, entity listeners, and global lifecycle listeners.
Default workflow
- Pick the narrowest mechanism: callback (one entity, no deps) โ entity listener (one entity, needs services) โ lifecycle listener (cross-cutting, all entities).
- Wire it with attributes (
#[ORM\HasLifecycleCallbacks],#[AsEntityListener],#[AsDoctrineListener]). - Type the event argument by its per-event class (
PostPersistEventArgs,PreUpdateEventArgs, โฆ). - Verify the side effect fires with a targeted functional test against a real DB.
This is the opening of the README. Read the full README on GitHub.