actiane/entity-change-watch-bundle
Symfony bundle to watch Doctrine entity lifecycle changes. Configure per-entity callbacks on create, update (all or specific properties), and delete. Invoke tagged services after flush with entity, changed properties, and EntityManager; supports pre-flush via flush:false.
prePersist, preUpdate, preRemove, etc.), making it a natural fit for systems requiring reactive validation, side-effect handling, or audit logging tied to entity state changes. Ideal for:
flush: false flag in create events may require careful handling to avoid partial updates if listeners throw exceptions.EventDispatcher, or packages like gedmo/doctrine-extensions (which includes change tracking).EventDispatcherComponent)?ChangeTrackingPolicy) or business rules (custom logic)?EntityListeners) to YAML.# Before: PHP class
$entityManager->getEventManager()->addEventListener(
KernelEvents::PRE_FLUSH,
[$myService, 'handlePreFlush']
);
# After: YAML
entity_change_watch:
classes:
App\Entity\MyEntity:
update:
properties:
status:
- {name: 'MyService', method: 'onStatusChange'}
EventArgs changes).postLoad in Doctrine 3.x).autoconfigure: true conflicts in services.yaml.DoctrineBundle must load first).STORED events in gedmo/doctrine-extensions).flush: false for create events).priority option if extending with custom services.LISTENERS.md file.actiane/entity-change-watch-bundle:^2.2).EventDispatcher).error_log("Listener triggered for " . $entity->getId())).debug:event-dispatcher to inspect event flow.try-catch to prevent silent rollbacks.public function doSomething(MyEntity $entity) {
try {
// Business logic
} catch (\Throwable $e) {
error_log("Listener failed for entity {$entity->getId()}: " . $e->getMessage());
throw $e; // Re-throw to rollback transaction
}
}
skipListeners flag in services).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Listener throws unhandled exception | Transaction rollback, partial state | Wrap in try-catch; log and re-throw. |
| Doctrine event system misconfigured | Events not fired | Test with debug:event-dispatcher. |
| YAML syntax error | Bundle fails to load | Use Symfony’s config validator. |
| PHP 8.x incompatibility | Runtime errors | Fork or use a poly |
How can I help you explore Laravel packages today?