EventDispatcher
class EventDispatcher
Handles operations related to dispatching events.
Properties
| protected array | $listeners | An array of registered listeners. |
Methods
Listens for an event.
Dispatches an event
Enqueue an event listener for asynchronous execution.
Determine if the listener should be enqueued and enqueue it if applicable.
Handle a registered listener in any supported shape.
Check if a listener provides custom queue preferences.
Process a listener provided as [FQCN|object, 'method'].
Process a listener provided as a fully-qualified class name.
Resolve the queue name for a queued listener or job.
Details
at line 28
void
listen(string $eventName, callable|string|array $listener)
Listens for an event.
at line 38
void
dispatch(object $event)
Dispatches an event
at line 61
private void
enqueueListener(string $listenerClass, object $instance, object $event)
Enqueue an event listener for asynchronous execution.
Builds a job payload from the listener and event, applies queue preferences (delay, backoff, max attempts) if the listener implements {\Core\Lib\Events\Contracts\QueuePreferences}, and pushes the job to the specified queue via the {\Core\Lib\Queue\QueueManager}.
at line 86
private bool
isEnqueueListener(string $listenerClass, object $instance, object $event)
Determine if the listener should be enqueued and enqueue it if applicable.
If the listener implements {\Core\Lib\Events\Contracts\ShouldQueue}, it will be dispatched to the queue system instead of being executed immediately.
at line 106
private void
handleListener(mixed $listener, object $event)
Handle a registered listener in any supported shape.
Supported forms:
- string FQCN: "App\Listeners\SendWelcomeEmail" (calls handle())
- array callable: [FQCN|object, 'method'] (calls given method)
at line 127
private bool
hasQueuePreferences(object $instance)
Check if a listener provides custom queue preferences.
at line 139
private void
processCallableArray(array $listener, object $event)
Process a listener provided as [FQCN|object, 'method'].
at line 161
private void
processClassString(string $listenerClass, object $event)
Process a listener provided as a fully-qualified class name.
Assumes a conventional handle($event) method.
at line 185
private string
setQueueName(object $instance)
Resolve the queue name for a queued listener or job.
If the given instance implements {\Core\Lib\Events\Contracts\QueuePreferences} and defines
a {\Core\Lib\Events\Contracts\QueuePreferences::viaQueue()} method, its return value will
be used as the queue name. If viaQueue() returns null or the method
does not exist, the queue name defaults to "default".