EventDispatcher
Dispatch events through PSR-14 listener providers and optional named wrappers.
Description
This dispatcher resolves listeners for the original event object first. When the event is not already a NamedEvent, it dispatches a named wrapper afterward so listeners registered by string identifier can observe the same event instance.
Interfaces
Properties
Methods
Create a dispatcher backed by the provided listener provider.
Dispatch an event to all matching listeners.
Invoke the provided listeners until propagation stops or a listener fails.
Dispatch an error event for a listener failure and rethrow the original throwable.
Create a dispatcher backed by the provided listener provider.
public
__construct(ListenerProviderInterface
$listenerProvider) : mixed
Parameters
$listenerProvider
:
ListenerProviderInterface
Description
listener provider used to resolve event listeners
Dispatch an event to all matching listeners.
public
dispatch(
object
$event[,
string|null
$eventName = null]) : object
Description
Stoppable events are returned immediately when propagation has already been halted. When a listener throws during a non-error dispatch, the dispatcher emits an ErrorEvent before rethrowing the original throwable.
Parameters
$event
:
object
Description
event object to dispatch
$eventName
:
string|null
=
null
Description
explicit name for the generated NamedEvent wrapper
Description
thrown when a listener failure is not absorbed by an error-event listener
Return values
Description
the dispatched event instance
Invoke the provided listeners until propagation stops or a listener fails.
private
callListeners(
iterable<string|int, callable>
$listeners,
object
$event) : void
Parameters
$listeners
:
iterable<string|int, callable>
Description
listeners resolved for the current event
$event
:
object
Description
event instance passed to each listener
Description
thrown when listener failure handling rethrows an error
Dispatch an error event for a listener failure and rethrow the original throwable.
private
handleThrowable(Throwable
$throwable,
object
$event,
callable
$listener) : void
Description
Error events are not wrapped again, which prevents recursive error dispatch when an error listener itself fails.
Parameters
$throwable
:
Throwable
Description
throwable raised by the listener
$event
:
object
Description
event being dispatched when the failure occurred
$listener
:
callable
Description
listener that raised the throwable
Description
always rethrows after attempting error dispatch