Symfony EventDispatcher Contracts
Generic PHP interfaces for dispatching events, decoupled from any concrete implementation.
Repository Health
Technical Analysis
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
EventDispatcherInterfaceextending PSR-14’s contract with a generics-annotateddispatch()method- A base
Eventclass implementingStoppableEventInterfacefor 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.