The Doctrine Common component comes with a built-in event system. It allows dispatching and subscribing to custom events, but its main purpose is to manage entity-related events.
In Chapter 1, Getting Started with Doctrine 2, we learned about entity managers, entity states, and Unit Of Work. Entity Managers (and their underlying
UnitOfWork objects) dispatch events when the state of the entity changes and when data is stored, updated, and removed from the database. They are called lifecycle events.
Doctrine also emits some events not directly related to the entity lifecycle.
Doctrine ORM provides the following bunch of lifecycle events:
preRemove: This event occurs when the state of the entity is set to