class Dispatcher implements Dispatcher

Properties

protected Container $container

The IoC container instance.

protected array $listeners

The registered event listeners.

protected array $wildcards

The wildcard listeners.

protected callable $queueResolver

The queue resolver instance.

Methods

void
__construct(Container $container = null)

Create a new event dispatcher instance.

void
listen(string|array $events, mixed $listener)

Register an event listener with the dispatcher.

void
setupWildcardListen(string $event, mixed $listener)

Setup a wildcard listener callback.

bool
hasListeners(string $eventName)

Determine if a given event has listeners.

void
push(string $event, array $payload = [])

Register an event and payload to be fired later.

void
flush(string $event)

Flush a set of pushed events.

void
subscribe(object|string $subscriber)

Register an event subscriber with the dispatcher.

mixed
resolveSubscriber(object|string $subscriber)

Resolve the subscriber instance.

array|null
until(string|object $event, mixed $payload = [])

Fire an event until the first non-null response is returned.

array|null
fire(string|object $event, mixed $payload = [], bool $halt = false)

Fire an event and call the listeners.

array|null
dispatch(string|object $event, mixed $payload = [], bool $halt = false)

Fire an event and call the listeners.

array
parseEventAndPayload(mixed $event, mixed $payload)

Parse the given event and payload and prepare them for dispatching.

bool
shouldBroadcast(array $payload)

Determine if the payload has a broadcastable event.

bool
broadcastWhen(mixed $event)

Check if event should be broadcasted by condition.

void
broadcastEvent(ShouldBroadcast $event)

Broadcast the given event class.

array
getListeners(string $eventName)

Get all of the listeners for a given event name.

array
getWildcardListeners(string $eventName)

Get the wildcard listeners for the event.

array
addInterfaceListeners(string $eventName, array $listeners = [])

Add the listeners for the event's interfaces to the given array.

makeListener(string|Closure $listener, bool $wildcard = false)

Register an event listener with the dispatcher.

createClassListener(string $listener, bool $wildcard = false)

Create a class based listener using the IoC container.

callable
createClassCallable(string $listener)

Create the class based event callable.

array
parseClassCallable(string $listener)

Parse the class listener into class and method.

bool
handlerShouldBeQueued(string $class)

Determine if the event handler class should be queued.

createQueuedHandlerCallable(string $class, string $method)

Create a callable for putting an event handler on the queue.

void
callQueueMethodOnHandler(string $class, string $method, array $arguments)

Call the queue method on the handler class.

void
queueHandler(string $class, string $method, array $arguments)

Queue the handler class.

array
createListenerAndJob(string $class, string $method, array $arguments)

Create the listener and job for a queued listener.

mixed
propogateListenerOptions(mixed $listener, mixed $job)

Propogate listener options to the job.

void
forget(string $event)

Remove a set of listeners from the dispatcher.

void
forgetPushed()

Forget all of the pushed listeners.

resolveQueue()

Get the queue implementation from the resolver.

$this
setQueueResolver(callable $resolver)

Set the queue resolver implementation.

Details

at line 51
void __construct(Container $container = null)

Create a new event dispatcher instance.

Parameters

Container $container

Return Value

void

at line 63
void listen(string|array $events, mixed $listener)

Register an event listener with the dispatcher.

Parameters

string|array $events
mixed $listener

Return Value

void

at line 81
protected void setupWildcardListen(string $event, mixed $listener)

Setup a wildcard listener callback.

Parameters

string $event
mixed $listener

Return Value

void

at line 92
bool hasListeners(string $eventName)

Determine if a given event has listeners.

Parameters

string $eventName

Return Value

bool

at line 104
void push(string $event, array $payload = [])

Register an event and payload to be fired later.

Parameters

string $event
array $payload

Return Value

void

at line 117
void flush(string $event)

Flush a set of pushed events.

Parameters

string $event

Return Value

void

at line 128
void subscribe(object|string $subscriber)

Register an event subscriber with the dispatcher.

Parameters

object|string $subscriber

Return Value

void

at line 141
protected mixed resolveSubscriber(object|string $subscriber)

Resolve the subscriber instance.

Parameters

object|string $subscriber

Return Value

mixed

at line 157
array|null until(string|object $event, mixed $payload = [])

Fire an event until the first non-null response is returned.

Parameters

string|object $event
mixed $payload

Return Value

array|null

at line 170
array|null fire(string|object $event, mixed $payload = [], bool $halt = false)

Fire an event and call the listeners.

Parameters

string|object $event
mixed $payload
bool $halt

Return Value

array|null

at line 183
array|null dispatch(string|object $event, mixed $payload = [], bool $halt = false)

Fire an event and call the listeners.

Parameters

string|object $event
mixed $payload
bool $halt

Return Value

array|null

at line 228
protected array parseEventAndPayload(mixed $event, mixed $payload)

Parse the given event and payload and prepare them for dispatching.

Parameters

mixed $event
mixed $payload

Return Value

array

at line 243
protected bool shouldBroadcast(array $payload)

Determine if the payload has a broadcastable event.

Parameters

array $payload

Return Value

bool

at line 256
protected bool broadcastWhen(mixed $event)

Check if event should be broadcasted by condition.

Parameters

mixed $event

Return Value

bool

at line 268
protected void broadcastEvent(ShouldBroadcast $event)

Broadcast the given event class.

Parameters

ShouldBroadcast $event

Return Value

void

at line 279
array getListeners(string $eventName)

Get all of the listeners for a given event name.

Parameters

string $eventName

Return Value

array

at line 298
protected array getWildcardListeners(string $eventName)

Get the wildcard listeners for the event.

Parameters

string $eventName

Return Value

array

at line 318
protected array addInterfaceListeners(string $eventName, array $listeners = [])

Add the listeners for the event's interfaces to the given array.

Parameters

string $eventName
array $listeners

Return Value

array

at line 338
Closure makeListener(string|Closure $listener, bool $wildcard = false)

Register an event listener with the dispatcher.

Parameters

string|Closure $listener
bool $wildcard

Return Value

Closure

at line 360
Closure createClassListener(string $listener, bool $wildcard = false)

Create a class based listener using the IoC container.

Parameters

string $listener
bool $wildcard

Return Value

Closure

at line 379
protected callable createClassCallable(string $listener)

Create the class based event callable.

Parameters

string $listener

Return Value

callable

at line 396
protected array parseClassCallable(string $listener)

Parse the class listener into class and method.

Parameters

string $listener

Return Value

array

at line 407
protected bool handlerShouldBeQueued(string $class)

Determine if the event handler class should be queued.

Parameters

string $class

Return Value

bool

at line 425
protected Closure createQueuedHandlerCallable(string $class, string $method)

Create a callable for putting an event handler on the queue.

Parameters

string $class
string $method

Return Value

Closure

at line 448
protected void callQueueMethodOnHandler(string $class, string $method, array $arguments)

Call the queue method on the handler class.

Parameters

string $class
string $method
array $arguments

Return Value

void

at line 465
protected void queueHandler(string $class, string $method, array $arguments)

Queue the handler class.

Parameters

string $class
string $method
array $arguments

Return Value

void

at line 488
protected array createListenerAndJob(string $class, string $method, array $arguments)

Create the listener and job for a queued listener.

Parameters

string $class
string $method
array $arguments

Return Value

array

at line 504
protected mixed propogateListenerOptions(mixed $listener, mixed $job)

Propogate listener options to the job.

Parameters

mixed $listener
mixed $job

Return Value

mixed

at line 518
void forget(string $event)

Remove a set of listeners from the dispatcher.

Parameters

string $event

Return Value

void

at line 532
void forgetPushed()

Forget all of the pushed listeners.

Return Value

void

at line 546
protected Queue resolveQueue()

Get the queue implementation from the resolver.

Return Value

Queue

at line 557
$this setQueueResolver(callable $resolver)

Set the queue resolver implementation.

Parameters

callable $resolver

Return Value

$this