Skip to content

EventDispatcher

A minimal PSR-14 dispatcher over a ListenerProvider.

Per PSR-14, the dispatcher does not swallow listener exceptions — a throwing listener propagates to the caller (fail-loud). Framework emit sites that must survive a misbehaving listener (the request pipeline) wrap their own EventDispatcher::dispatch() call in try/catch; see Events call sites.

final class EventDispatcher implements EventDispatcherInterface

ImplementsEventDispatcherInterface
SourceEvent/EventDispatcher.php

public function __construct(ListenerProvider $provider = new ListenerProvider(…)): mixed

ParameterTypeDescription
$providerListenerProvider

Returns mixed

MethodDescription
dispatch(object $event): objectPasses the event to every matching listener and returns the same instance.
provider(): ListenerProviderReturns the listener provider this dispatcher draws its listeners from, for registration.

public function dispatch(object $event): object

Passes the event to every matching listener and returns the same instance.

Listeners run in the order the provider yields them (priority first, then registration order). If the event implements StoppableEventInterface, propagation is checked before the first listener — an already-stopped event is returned untouched — and again after each listener, breaking out as soon as one stops it. Listener exceptions are not caught and propagate to the caller.

ParameterTypeDescription
$eventobject

Returns object

public function provider(): ListenerProvider

Returns the listener provider this dispatcher draws its listeners from, for registration.

Returns ListenerProvider