Doctrine Event Manager

A simple, dependency-free PHP event dispatcher built to power Doctrine's lifecycle events

Library
Composer
v2.1.1
6,044stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
54/100Fair
Development Activity32
Maintenance28
Community56
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
75/100Good
Architecture75
Code Quality80
Innovation60
Learning Curve85

Doctrine Event Manager is a small, standalone PHP library implementing a straightforward event dispatcher: listeners register interest in named events, and an EventManager fires those events with an EventArgs payload. It underpins Doctrine ORM’s entity lifecycle callbacks (prePersist, postLoad, preUpdate, and so on) as well as extension libraries that hook into those lifecycle points, but has no hard dependency on Doctrine ORM itself.

The library favors a minimal, closure-free design — listeners are plain objects implementing named methods, discovered via an EventListenerRegistry, or EventSubscriber objects that declare the events they care about — making it easy to reason about which code runs in response to which event without a heavier pub/sub or message-bus abstraction.

What You Get

  • EventManager for registering listeners and dispatching named events
  • EventArgs base class for passing event payload data to listeners
  • EventSubscriber interface for objects that declare a set of events they listen to
  • EventListenerRegistry / EventSubscriberRegistry for organizing registered listeners
  • EventListenerIntrospector for inspecting which listeners are registered for a given event

Common Use Cases

  • Hooking into Doctrine ORM entity lifecycle events (prePersist, postLoad, preUpdate, etc.)
  • Building Doctrine extension libraries (e.g. soft-delete, timestampable behaviors) that react to persistence events
  • Implementing a lightweight in-process event system without pulling in a full message bus
  • Decoupling cross-cutting concerns (logging, auditing) from core business logic via listeners

Under The Hood

Architecture - EventManager (src/EventManager.php) is the central dispatcher: it holds a map of event name to listener objects and exposes dispatchEvent(), which invokes the method named after the event on each registered listener, passing an EventArgs instance. EventSubscriber (src/EventSubscriber.php) lets a single class declare multiple events via getSubscribedEvents(), registered in bulk rather than one listener call at a time; EventListenerRegistry/EventSubscriberRegistry track what’s registered, and EventListenerIntrospector exposes that state for debugging/tooling. There is no queueing, async dispatch, or priority system — dispatch is synchronous, in-process, and listeners run in registration order. Tech Stack - Pure PHP (100%) requiring PHP 8.1+, with zero runtime dependencies; PHPStan and doctrine/coding-standard run in CI, and PHPUnit 10 covers the test suite. Code Quality - The tests/ directory exercises listener registration, subscriber-based bulk registration, and dispatch ordering; the codebase is small (eight classes) and fully typed with PHP 8 property/return types, making it easy to audit end to end. API Design - The API is deliberately minimal: addEventListener, addEventSubscriber, and dispatchEvent cover nearly every use case, and listener methods are named directly after the event they respond to, so wiring a new listener requires no configuration beyond implementing a method with a matching name.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search