Symfony EventDispatcher Contracts

Generic PHP interfaces for dispatching events, decoupled from any concrete implementation.

Library
Composer
vv3.7.1
3,413stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
56/100Fair
Development Activity40
Maintenance32
Community52
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
66/100Good
Architecture70
Code Quality55
Innovation65
Learning Curve75

Symfony EventDispatcher Contracts is a minimal set of PHP interfaces extracted from the Symfony EventDispatcher component. It defines the EventDispatcherInterface (extending PSR-14’s EventDispatcherInterface) and a base Event class supporting propagation stopping, without pulling in a concrete dispatcher implementation.

Libraries and applications can type-hint against these contracts instead of a specific event-dispatching library, letting any PSR-14-compatible dispatcher be swapped in. It is one of several symfony/*-contracts packages (alongside cache, http-client, translation, and others) that Symfony publishes to decouple its components’ public APIs from their implementations.

What You Get

  • EventDispatcherInterface extending PSR-14’s contract with a generics-annotated dispatch() method
  • A base Event class implementing StoppableEventInterface for propagation control
  • Zero runtime dependencies beyond psr/event-dispatcher
  • Semantic-versioned contracts safe to depend on without pulling in Symfony’s full EventDispatcher implementation

Common Use Cases

  • Library authors who want to dispatch events without forcing consumers to install a specific dispatcher implementation
  • Symfony bundle developers building on the framework’s event system while keeping a narrow dependency surface
  • PHP packages that want a stable, framework-agnostic event abstraction compatible with PSR-14

Under The Hood

Architecture — The package is intentionally tiny: two files totaling under 3KB. EventDispatcherInterface extends the PSR-14 Psr\EventDispatcher\EventDispatcherInterface, narrowing the dispatch() signature to accept an optional $eventName and documenting via @template T of object that the passed event object is returned unchanged (useful for static analysis). Event implements StoppableEventInterface with a private $propagationStopped flag toggled via stopPropagation() and read via isPropagationStopped() — no dispatch logic lives here; that’s left to concrete implementations such as symfony/event-dispatcher.

Tech Stack — Pure PHP 8.1+, PSR-4 autoloaded under the Symfony\Contracts\EventDispatcher namespace. The only dependency is psr/event-dispatcher (^1). No build step, no compiled assets — it’s shipped as-is via Composer.

Code Quality — There are no tests in this repository; as a pure-interface/abstract-class package, correctness is enforced by consumers’ own test suites and by Symfony’s broader contracts test coverage in the symfony/contracts monorepo. Code follows Symfony’s strict coding standards: typed properties, return types on every method, and PHPDoc for generics-style hints PHP itself doesn’t natively support.

API Design — The API surface is deliberately minimal — two types, four public methods total. This is by design: consuming code type-hints against EventDispatcherInterface and Event/StoppableEventInterface, and any PSR-14-compliant dispatcher can be substituted at runtime with zero code changes on the consumer side.

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