O'Reilly logo

Persistence in PHP with Doctrine ORM by Kévin Dunglas

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Getting started with events

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.

Note

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 removed
  • postRemove ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required