---
name: Symfony Doctrine Events
slug: symfony-doctrine-events
category: DevOps
description: Symfony Doctrine Events shows how to react to Doctrine entity lifecycle changes with callbacks, entity listeners, and lifecycle listeners in ORM 3. Use it for timestamps, slugs, indexing, notifications, and testing persistence side effects.
github: "https://github.com/dev-toolings/superpowers-symfony/tree/main/skills/doctrine-events"
language: TypeScript
stars: 208
forks: 20
install: "npx degit https://github.com/dev-toolings/superpowers-symfony/tree/main/skills/doctrine-events ~/.claude/skills/doctrine-events"
installs_to: ~/.claude/skills/doctrine-events
source_path: skills/doctrine-events/SKILL.md
collection_size: 23
category_size: 920
collection_url: "https://dirskills.com/collections/dev-toolings/superpowers-symfony"
added: 2026-09-04T05:27:06.511Z
last_synced: 2026-09-04T05:27:06.511Z
canonical_url: "https://dirskills.com/skills/symfony-doctrine-events"
---

# Symfony Doctrine Events

Symfony Doctrine Events shows how to react to Doctrine entity lifecycle changes with callbacks, entity listeners, and lifecycle listeners in ORM 3. Use it for timestamps, slugs, indexing, notifications, and testing persistence side effects.

**Install:**

```bash
npx degit https://github.com/dev-toolings/superpowers-symfony/tree/main/skills/doctrine-events ~/.claude/skills/doctrine-events
```

## README

# Doctrine Events (Symfony)

## Use when
- You need side effects on entity persistence (timestamps, slugs, search indexing, notifications).
- Migrating an `EventSubscriberInterface` Doctrine subscriber to ORM 3.
- Choosing between lifecycle callbacks, entity listeners, and global lifecycle listeners.

## Default workflow
1. Pick the narrowest mechanism: callback (one entity, no deps) → entity listener (one entity, needs services) → lifecycle listener (cross-cutting, all entities).
2. Wire it with attributes (`#[ORM\HasLifecycleCallbacks]`, `#[AsEntityListener]`, `#[AsDoctrineListener]`).
3. Type the event argument by its per-event class (`PostPersistEventArgs`, `PreUpdateEventArgs`, …).
4. Verify the side effect fires with a targeted functional test against a real DB.

## Guardrails
- ORM 3.0 removed `EventSubscriberInterface` Doctrine subscribers — never reintroduce them.
- Type-check the entity early in a global lifecycle listener (it fires for every entity).
- Never call `flush()` inside a Doctrine event handler — it corrupts the in-flight unit of work.
- `preUpdate` is restricted: change fields only via `$args->setNewValue()`, never touch associations.

## Progressive disclosure
- Use this file for execution posture and risk controls.
- Open `reference.md` for the three mechanisms, the event-args matrix, and migration from subscribers.

## Output contract
- Listener/callback class with the correct attribute.
- Justification for the chosen mechanism.
- Validation outcomes (test that the side effect fired).

## References
- `reference.md`
- `docs/complexity-tiers.md`
