Dispatcher
class Dispatcher implements Dispatcher
Traits
Constants
| DEFERRING_CONTEXT_KEY |
Context key for whether event deferral is active. |
| DEFERRED_EVENTS_CONTEXT_KEY |
Context key for the queue of deferred events. |
| EVENTS_TO_DEFER_CONTEXT_KEY |
Context key for the list of event classes to defer. |
| PUSHED_EVENTS_CONTEXT_KEY |
Context key for events queued via push() and dispatched via flush(). |
Properties
| static protected array | $macros | The registered string macros. |
from Macroable |
| protected Container | $container | The IoC container instance. |
|
| protected array<array-key, array<int, null|array|callable|string>> | $listeners | The registered event listeners. |
|
| protected array<string, array<int, array|callable|string>> | $wildcards | The wildcard listeners. |
|
| protected array<string, true> | $interfaceListeners | The registered interface listener keys. |
|
| protected Closure>> | $preparedListeners | The prepared event listeners keyed by registered event name. |
|
| protected Closure>> | $preparedWildcardListeners | The prepared wildcard listeners keyed by registered pattern. |
|
| protected array<string, array<int, array|callable|string>> | $observers | The registered event observers. |
|
| protected array<string, array<int, array|callable|string>> | $observerWildcards | The wildcard observers. |
|
| protected array<string, string> | $compiledWildcardPatterns | The compiled listener and observer wildcard patterns. |
|
| protected Closure>> | $preparedObservers | The prepared event observers keyed by registered event name. |
|
| protected Closure>> | $preparedWildcardObservers | The prepared wildcard observers keyed by registered pattern. |
|
| protected Factory | $queueResolver | The queue resolver instance. |
|
| protected callable | $transactionManagerResolver | The database transaction manager resolver instance. |
Methods
Mix another object into the class.
Dynamically handle calls to the class.
Dynamically handle calls to the class.
Get a configuration value from an attribute, falling back to a property.
Extract the value from an attribute instance.
Get an instance of the given attribute class from the target class or its parents.
Determine if a property declared on a child class overrides an inherited attribute.
Get the class name of the first parameter of the given Closure.
Get the class names of the first parameter of the given Closure, including union types.
Get the class names / types of the parameters of the given Closure.
Get the class names / types of the return type of the given Closure.
Resolve the default connection name for a given queueable instance.
Resolve the default queue name for a given queueable instance.
Get the container that owns the queue routes.
Register an event listener with the dispatcher.
Set up a wildcard listener callback.
Register a passive event observer.
Set up a wildcard observer callback.
Compile a case-sensitive wildcard pattern.
Determine if a given event has listeners.
Determine if the given event has any wildcard listeners.
Determine if the event class implements an interface with listeners.
Determine if interface listeners should be resolved for the event.
Register an event and payload to be fired later.
Flush a set of pushed events.
Register an event subscriber with the dispatcher.
Resolve the subscriber instance.
Fire an event until the first non-null response is returned.
Fire an event and call the listeners.
Broadcast an event and call its listeners.
Invoke active listeners followed by passive observers.
Invoke passive observers for the event.
Parse the given event and payload and prepare them for dispatching.
Determine if the payload has a broadcastable event.
Check if the event should be broadcasted by the condition.
Get all of the listeners for a given event name.
Get the wildcard listeners for the event.
Prepare the listeners for a registered wildcard pattern.
Add the listeners for the event's interfaces to the given array.
Prepare the listeners for a given event.
Get all observers for a given event name.
Prepare the observers for a given event.
Get the wildcard observers for the event.
Prepare the observers for a registered wildcard pattern.
Register an event listener with the dispatcher.
Create a callable for the given observer.
Create a class based listener using the IoC container.
Create the class based event callable.
Parse the class listener into class and method.
Determine if the event handler class should be queued.
Create a callable for putting an event handler on the queue.
Determine if the given event handler should be dispatched after the open parent database transactions have committed.
Create a callable for dispatching a listener after database transactions.
Determine if the event handler wants to be queued.
Queue the handler class.
Create the listener and job for a queued listener.
Propagate listener options to the job.
Remove a set of listeners from the dispatcher.
Forget all events queued via push() in the current coroutine.
Get the queue implementation from the resolver.
Set the queue resolver implementation.
Get the database transaction manager implementation from the resolver.
Set the database transaction manager resolver implementation.
Execute the given callback while deferring events, then dispatch all deferred events.
Determine if the given event should be deferred.
Get the raw, unprepared listeners.
Flush all static state.
Details
in
Macroable at line 30
static void
macro(string $name, callable|object $macro)
Register a custom macro.
Macros persist in a static property for the worker lifetime and apply to every subsequent call on the macroable class.
in
Macroable at line 44
static void
mixin(object $mixin, bool $replace = true)
Mix another object into the class.
Delegates to macro() for each method; registered macros persist in a static property for the worker lifetime.
in
Macroable at line 61
static bool
hasMacro(string $name)
Check if macro is registered.
in
Macroable at line 72
static void
flushMacros()
Flush the existing macros.
Clears worker-wide macros; concurrent coroutines may resolve different methods depending on timing.
in
Macroable at line 83
static mixed
__callStatic(string $method, array $parameters)
Dynamically handle calls to the class.
in
Macroable at line 108
mixed
__call(string $method, array $parameters)
Dynamically handle calls to the class.
in
ReadsClassAttributes at line 17
protected mixed
getAttributeValue(object $target, string $attributeClass, string|null $property = null, mixed $default = null)
Get a configuration value from an attribute, falling back to a property.
in
ReadsClassAttributes at line 46
protected mixed
extractAttributeValue(object $instance)
Extract the value from an attribute instance.
in
ReadsClassAttributes at line 58
protected object|null
getAttributeInstance(object $target, string $attributeClass, ReflectionClass|null $declaringClass = null)
Get an instance of the given attribute class from the target class or its parents.
in
ReadsClassAttributes at line 74
protected bool
propertyOverridesAttribute(object $target, ReflectionClass $reflection, string|null $property, ReflectionClass $attributeDeclaringClass)
Determine if a property declared on a child class overrides an inherited attribute.
in
ReflectsClosures at line 26
protected string
firstClosureParameterType(Closure $closure)
Get the class name of the first parameter of the given Closure.
in
ReflectsClosures at line 49
protected array
firstClosureParameterTypes(Closure $closure)
Get the class names of the first parameter of the given Closure, including union types.
in
ReflectsClosures at line 75
protected array
closureParameterTypes(Closure $closure)
Get the class names / types of the parameters of the given Closure.
in
ReflectsClosures at line 97
protected array
closureReturnTypes(Closure $closure)
Get the class names / types of the return type of the given Closure.
in
ResolvesQueueRoutes at line 19
string|null
resolveConnectionFromQueueRoute(object $queueable, UnitEnum|string|null $queue = null)
Resolve the default connection name for a given queueable instance.
in
ResolvesQueueRoutes at line 27
string|null
resolveQueueFromQueueRoute(object $queueable)
Resolve the default queue name for a given queueable instance.
in
ResolvesQueueRoutes at line 35
protected QueueRoutes
queueRoutes()
Get the queue routes manager instance.
at line 1159
protected Container
queueRoutesContainer()
Get the container that owns the queue routes.
at line 182
__construct(Container|null $container = null)
Create a new event dispatcher instance.
at line 193
void
listen(array|Closure|QueuedClosure|string $events, array|object|string|null $listener = null)
Register an event listener with the dispatcher.
The listener registry persists on the singleton Dispatcher for the worker lifetime; per-request registration races across coroutines.
at line 243
protected void
setupWildcardListen(string $event, array|object|string $listener)
Set up a wildcard listener callback.
at line 265
void
observe(array|string $events, array|object|string $observer)
Register a passive event observer.
The observer registry persists on the singleton Dispatcher for the worker lifetime; per-request registration races across coroutines.
Observers receive dispatched events but are not counted by hasListeners(). They run after active listener processing ends, including ordinary listener failure, do not participate in halt or propagation-stop semantics, and run synchronously (no queue support). Every observer is attempted before the first ordinary observer failure is rethrown. Cancellation stops observation.
Use this for observability tooling (tracing, metrics, logging) that must not influence whether guarded events fire.
at line 281
protected void
setupWildcardObserver(string $event, array|object|string $observer)
Set up a wildcard observer callback.
at line 291
protected string
compileWildcardPattern(string $pattern)
Compile a case-sensitive wildcard pattern.
at line 302
bool
hasListeners(string $eventName)
Determine if a given event has listeners.
at line 313
bool
hasWildcardListeners(string $eventName)
Determine if the given event has any wildcard listeners.
at line 328
protected bool
hasInterfaceListeners(string $eventName)
Determine if the event class implements an interface with listeners.
at line 349
protected bool
shouldResolveInterfaceListeners(string $eventName)
Determine if interface listeners should be resolved for the event.
Relies on interface listener keys being classified at registration time.
at line 357
void
push(string $event, mixed $payload = [])
Register an event and payload to be fired later.
at line 370
void
flush(string $event)
Flush a set of pushed events.
at line 383
void
subscribe(object|string $subscriber)
Register an event subscriber with the dispatcher.
Subscriber registrations persist on the singleton Dispatcher for the worker lifetime; per-request registration races across coroutines.
at line 410
protected mixed
resolveSubscriber(object|string $subscriber)
Resolve the subscriber instance.
at line 422
mixed
until(object|string $event, mixed $payload = [])
Fire an event until the first non-null response is returned.
at line 432
mixed
dispatch(object|string $event, mixed $payload = [], bool $halt = false)
Fire an event and call the listeners.
at line 472
protected mixed
invokeListeners(string $event, array $payload, bool $halt = false)
Broadcast an event and call its listeners.
at line 511
protected mixed
invokeListenersAndObservers(string $event, array $payload, bool $halt = false)
Invoke active listeners followed by passive observers.
An ordinary active listener failure remains primary after every observer is attempted. Cancellation from either path stops observation and escapes.
at line 546
protected void
invokeObservers(string $event, array $payload)
Invoke passive observers for the event.
Observers do not participate in halt or propagation-stop semantics. Every observer is attempted after ordinary failure, their return values are ignored, and the first ordinary failure is rethrown. Cancellation stops the observer sequence immediately.
at line 572
protected array
parseEventAndPayload(object|string $event, mixed $payload)
Parse the given event and payload and prepare them for dispatching.
at line 584
protected bool
shouldBroadcast(array $payload)
Determine if the payload has a broadcastable event.
at line 594
protected bool
broadcastWhen(mixed $event)
Check if the event should be broadcasted by the condition.
at line 604
protected void
broadcastEvent(ShouldBroadcast $event)
Broadcast the given event class.
at line 612
array
getListeners(string $eventName)
Get all of the listeners for a given event name.
at line 629
protected array
getWildcardListeners(string $eventName)
Get the wildcard listeners for the event.
at line 647
protected array
prepareWildcardListeners(string $eventName)
Prepare the listeners for a registered wildcard pattern.
at line 663
protected array
addInterfaceListeners(string $eventName, array $listeners = [])
Add the listeners for the event's interfaces to the given array.
at line 679
protected array
prepareListeners(string $eventName)
Prepare the listeners for a given event.
at line 699
array
getObservers(string $eventName)
Get all observers for a given event name.
at line 716
protected array
prepareObservers(string $eventName)
Prepare the observers for a given event.
at line 736
protected array
getWildcardObservers(string $eventName)
Get the wildcard observers for the event.
at line 754
protected array
prepareWildcardObservers(string $eventName)
Prepare the observers for a registered wildcard pattern.
at line 772
Closure
makeListener(array|object|string $listener, bool $wildcard = false)
Register an event listener with the dispatcher.
at line 798
protected Closure
makeObserver(array|object|string $observer)
Create a callable for the given observer.
Unlike makeListener(), this never consults queue or after-commit logic. Observers are always invoked synchronously and always receive the wildcard-style (string $event, array $payload) arguments.
at line 820
Closure
createClassListener(array|string $listener, bool $wildcard = false)
Create a class based listener using the IoC container.
at line 838
protected callable
createClassCallable(array|string $listener)
Create the class based event callable.
at line 869
protected array
parseClassCallable(string $listener)
Parse the class listener into class and method.
at line 881
protected bool
handlerShouldBeQueued(string $class)
Determine if the event handler class should be queued.
at line 898
protected Closure
createQueuedHandlerCallable(string $class, string $method)
Create a callable for putting an event handler on the queue.
at line 914
protected bool
handlerShouldBeDispatchedAfterDatabaseTransactions(mixed $listener)
Determine if the given event handler should be dispatched after the open parent database transactions have committed.
at line 924
protected Closure
createCallbackForListenerRunningAfterCommits(mixed $listener, string $method)
Create a callable for dispatching a listener after database transactions.
at line 942
protected bool
handlerWantsToBeQueued(string $class, array $arguments)
Determine if the event handler wants to be queued.
at line 958
protected void
queueHandler(string $class, string $method, array $arguments)
Queue the handler class.
at line 1035
protected array
createListenerAndJob(string $class, string $method, array $arguments)
Create the listener and job for a queued listener.
at line 1048
protected CallQueuedListener
propagateListenerOptions(mixed $listener, CallQueuedListener $job)
Propagate listener options to the job.
at line 1118
void
forget(string $event)
Remove a set of listeners from the dispatcher.
The listener registry persists on the singleton Dispatcher for the worker lifetime; per-request removal races across coroutines and can remove application listeners for other requests.
at line 1143
void
forgetPushed()
Forget all events queued via push() in the current coroutine.
at line 1151
protected Factory
resolveQueue()
Get the queue implementation from the resolver.
at line 1173
Dispatcher
setQueueResolver(callable $resolver)
Set the queue resolver implementation.
The resolver persists on the singleton Dispatcher for the worker lifetime and is consulted whenever a queued listener is dispatched.
at line 1184
protected DatabaseTransactionsManager|null
resolveTransactionManager()
Get the database transaction manager implementation from the resolver.
at line 1202
Dispatcher
setTransactionManagerResolver(callable $resolver)
Set the database transaction manager resolver implementation.
The resolver persists on the singleton Dispatcher for the worker lifetime and is consulted for every transaction-aware dispatch.
at line 1219
mixed
defer(callable $callback, array|null $events = null)
Execute the given callback while deferring events, then dispatch all deferred events.
at line 1249
protected bool
shouldDeferEvent(string $event)
Determine if the given event should be deferred.
at line 1265
array
getRawListeners()
Get the raw, unprepared listeners.
at line 1273
static void
flushState()
Flush all static state.