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<string, 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>> | $wildcardsCache | The cached wildcard listeners. |
|
| protected array | $listenersCache | The cached prepared listeners. |
|
| protected array<string, bool> | $hasListenersCache | The cached hasListeners results. |
|
| 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 Closure>> | $observerWildcardsCache | The cached wildcard observers. |
|
| protected Closure>> | $observersCache | The cached prepared observers. |
|
| 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.
Register an event listener with the dispatcher.
Set up a wildcard listener callback.
Register a passive event observer.
Set up a wildcard observer callback.
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 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.
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.
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 all 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 28
static void
macro(string $name, callable|object $macro)
Register a custom macro.
Boot-only. Macros persist in a static property for the worker lifetime and apply to every subsequent call on the macroable class.
in
Macroable at line 41
static void
mixin(object $mixin, bool $replace = true)
Mix another object into the class.
Boot-only. Delegates to macro() for each method; registered macros persist in a static property for the worker lifetime.
in
Macroable at line 57
static bool
hasMacro(string $name)
Check if macro is registered.
in
Macroable at line 68
static void
flushMacros()
Flush the existing macros.
Boot or tests only. Clears worker-wide macros; concurrent coroutines may resolve different methods depending on timing.
in
Macroable at line 78
static mixed
__callStatic(string $method, array $parameters)
Dynamically handle calls to the class.
in
Macroable at line 103
mixed
__call(string $method, array $parameters)
Dynamically handle calls to the class.
in
ReadsClassAttributes at line 15
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 44
protected mixed
extractAttributeValue(object $instance)
Extract the value from an attribute instance.
in
ReadsClassAttributes at line 54
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 70
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 25
protected string
firstClosureParameterType(Closure $closure)
Get the class name of the first parameter of the given Closure.
in
ReflectsClosures at line 48
protected array
firstClosureParameterTypes(Closure $closure)
Get the class names of the first parameter of the given Closure, including union types.
in
ReflectsClosures at line 74
protected array
closureParameterTypes(Closure $closure)
Get the class names / types of the parameters of the given Closure.
in
ReflectsClosures at line 94
protected array
closureReturnTypes(Closure $closure)
Get the class names / types of the return type of the given Closure.
in
ResolvesQueueRoutes at line 15
string|null
resolveConnectionFromQueueRoute(object $queueable)
Resolve the default connection name for a given queueable instance.
in
ResolvesQueueRoutes at line 23
string|null
resolveQueueFromQueueRoute(object $queueable)
Resolve the default queue name for a given queueable instance.
in
ResolvesQueueRoutes at line 31
protected QueueRoutes
queueRoutes()
Get the queue routes manager instance.
at line 173
__construct(Container|null $container = null)
Create a new event dispatcher instance.
at line 184
void
listen(array|Closure|QueuedClosure|string $events, array|object|string|null $listener = null)
Register an event listener with the dispatcher.
Boot-only. The listener registry persists on the singleton Dispatcher for the worker lifetime; per-request registration races across coroutines.
at line 235
protected void
setupWildcardListen(string $event, array|object|string $listener)
Set up a wildcard listener callback.
at line 257
void
observe(array|string $events, array|object|string $observer)
Register a passive event observer.
Boot-only. 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 are invoked after all active listeners, do not participate in halt or propagation-stop semantics, and run synchronously (no queue support).
Use this for observability tooling (tracing, metrics, logging) that must not influence whether guarded events fire.
at line 274
protected void
setupWildcardObserver(string $event, array|object|string $observer)
Set up a wildcard observer callback.
at line 285
bool
hasListeners(string $eventName)
Determine if a given event has listeners.
at line 300
bool
hasWildcardListeners(string $eventName)
Determine if the given event has any wildcard listeners.
at line 314
protected bool
hasInterfaceListeners(string $eventName)
Determine if the event class implements an interface with listeners.
at line 334
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 342
void
push(string $event, mixed $payload = [])
Register an event and payload to be fired later.
at line 355
void
flush(string $event)
Flush a set of pushed events.
at line 368
void
subscribe(object|string $subscriber)
Register an event subscriber with the dispatcher.
Boot-only. Subscriber registrations persist on the singleton Dispatcher for the worker lifetime; per-request registration races across coroutines.
at line 392
protected mixed
resolveSubscriber(object|string $subscriber)
Resolve the subscriber instance.
at line 404
mixed
until(object|string $event, mixed $payload = [])
Fire an event until the first non-null response is returned.
at line 412
mixed
dispatch(object|string $event, mixed $payload = [], bool $halt = false)
Fire an event and call the listeners.
at line 457
protected mixed
invokeListeners(string $event, array $payload, bool $halt = false)
Broadcast an event and call its listeners.
at line 496
protected void
invokeObservers(string $event, array $payload)
Invoke passive observers for the event.
Observers do not participate in halt or propagation-stop semantics. They always run, and their return values are ignored.
at line 508
protected array
parseEventAndPayload(object|string $event, mixed $payload)
Parse the given event and payload and prepare them for dispatching.
at line 520
protected bool
shouldBroadcast(array $payload)
Determine if the payload has a broadcastable event.
at line 530
protected bool
broadcastWhen(mixed $event)
Check if the event should be broadcasted by the condition.
at line 540
protected void
broadcastEvent(ShouldBroadcast $event)
Broadcast the given event class.
at line 548
array
getListeners(string $eventName)
Get all of the listeners for a given event name.
at line 569
protected array
getWildcardListeners(string $eventName)
Get the wildcard listeners for the event.
at line 587
protected array
addInterfaceListeners(string $eventName, array $listeners = [])
Add the listeners for the event's interfaces to the given array.
at line 605
protected array
prepareListeners(string $eventName)
Prepare the listeners for a given event.
at line 619
array
getObservers(string $eventName)
Get all observers for a given event name.
at line 638
protected array
prepareObservers(string $eventName)
Prepare the observers for a given event.
at line 652
protected array
getWildcardObservers(string $eventName)
Get the wildcard observers for the event.
at line 670
Closure
makeListener(array|object|string $listener, bool $wildcard = false)
Register an event listener with the dispatcher.
at line 696
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 718
Closure
createClassListener(array|string $listener, bool $wildcard = false)
Create a class based listener using the IoC container.
at line 736
protected callable
createClassCallable(array|string $listener)
Create the class based event callable.
at line 767
protected array
parseClassCallable(string $listener)
Parse the class listener into class and method.
at line 775
protected bool
handlerShouldBeQueued(string $class)
Determine if the event handler class should be queued.
at line 791
protected Closure
createQueuedHandlerCallable(string $class, string $method)
Create a callable for putting an event handler on the queue.
at line 807
protected bool
handlerShouldBeDispatchedAfterDatabaseTransactions(mixed $listener)
Determine if the given event handler should be dispatched after all database transactions have committed.
at line 817
protected Closure
createCallbackForListenerRunningAfterCommits(mixed $listener, string $method)
Create a callable for dispatching a listener after database transactions.
at line 835
protected bool
handlerWantsToBeQueued(string $class, array $arguments)
Determine if the event handler wants to be queued.
at line 851
protected void
queueHandler(string $class, string $method, array $arguments)
Queue the handler class.
at line 903
protected array
createListenerAndJob(string $class, string $method, array $arguments)
Create the listener and job for a queued listener.
at line 916
protected CallQueuedListener
propagateListenerOptions(mixed $listener, CallQueuedListener $job)
Propagate listener options to the job.
at line 969
void
forget(string $event)
Remove a set of listeners from the dispatcher.
Boot or tests only. 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 997
void
forgetPushed()
Forget all events queued via push() in the current coroutine.
at line 1005
protected Factory
resolveQueue()
Get the queue implementation from the resolver.
at line 1018
Dispatcher
setQueueResolver(callable $resolver)
Set the queue resolver implementation.
Boot-only. The resolver persists on the singleton Dispatcher for the worker lifetime and is consulted whenever a queued listener is dispatched.
at line 1028
protected DatabaseTransactionsManager|null
resolveTransactionManager()
Get the database transaction manager implementation from the resolver.
at line 1045
Dispatcher
setTransactionManagerResolver(callable $resolver)
Set the database transaction manager resolver implementation.
Boot-only. The resolver persists on the singleton Dispatcher for the worker lifetime and is consulted for every transaction-aware dispatch.
at line 1061
mixed
defer(callable $callback, array|null $events = null)
Execute the given callback while deferring events, then dispatch all deferred events.
at line 1091
protected bool
shouldDeferEvent(string $event)
Determine if the given event should be deferred.
at line 1105
array
getRawListeners()
Get the raw, unprepared listeners.
at line 1113
static void
flushState()
Flush all static state.