Skip to content

EloquentMinimalEventDispatcher

A minimal Illuminate\Contracts\Events\Dispatcher implementation, used only as the fallback EloquentQueryRecorder::attach() installs on a Illuminate\Database\Connection that has no event dispatcher of its own — which is the case for Quiote\Database\Adapter\Eloquent\EloquentDatabase’s connect(), which never calls Capsule::setEventDispatcher().

illuminate/events is not a dependency of this codebase (or of illuminate/database itself), so this exists rather than pulling in the full package for one interface.

Supports exactly what Illuminate\Database\Connection actually calls on a connection-level event dispatcher: listen()/dispatch()/hasListeners() for query, transaction and connection-lifecycle events, and until() as a thin wrapper over dispatch(). The queued-event API (push()/flush()/ forgetPushed()) and subscribe() are not part of that surface and are intentionally unimplemented (no-ops / throwing) — if an application attaches this to anything beyond a single DB connection, that is a sign it needs a real event dispatcher, not this one.

final class EloquentMinimalEventDispatcher implements Dispatcher

ImplementsDispatcher
SourceEloquentMinimalEventDispatcher.php
MethodDescription
[`dispatch(stringobject $event, array<int, mixed> $payload = [], bool $halt = false): mixed`](#dispatch)
flush(string $event): voidFlush a set of pushed events.
forget(string $event): voidRemove a set of listeners from the dispatcher.
forgetPushed(): voidForget all of the queued listeners.
hasListeners(string $eventName): boolDetermine if a given event has listeners.
[`listen(Closurestring
push(string $event, array<int, mixed> $payload = []): voidRegister an event and payload to be fired later.
[`subscribe(objectstring $subscriber): void`](#subscribe)
[`until(stringobject $event, array<int, mixed> $payload = []): mixed`](#until)

public function dispatch(string|object $event, array<int, mixed> $payload = [], bool $halt = false): mixed

Dispatch an event and call the listeners.

ParameterTypeDescription
$event`string““object`
$payloadarray``<``int``, ``mixed``>
$haltbool

Returns mixed

public function flush(string $event): void

Flush a set of pushed events.

ParameterTypeDescription
$eventstring

public function forget(string $event): void

Remove a set of listeners from the dispatcher.

ParameterTypeDescription
$eventstring

public function forgetPushed(): void

Forget all of the queued listeners.

public function hasListeners(string $eventName): bool

Determine if a given event has listeners.

ParameterTypeDescription
$eventNamestring

Returns bool

public function listen(Closure|string|array<int, string> $events, Closure|string|array<int, string>|null $listener = null): void

Register an event listener with the dispatcher.

ParameterTypeDescription
$eventsClosure`string
$listenerClosure`string

public function push(string $event, array<int, mixed> $payload = []): void

Register an event and payload to be fired later.

ParameterTypeDescription
$eventstring
$payloadarray``<``int``, ``mixed``>

public function subscribe(object|string $subscriber): void

Register an event subscriber with the dispatcher.

ParameterTypeDescription
$subscriber`object““string`

public function until(string|object $event, array<int, mixed> $payload = []): mixed

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

ParameterTypeDescription
$event`string““object`
$payloadarray``<``int``, ``mixed``>

Returns mixed