trait HasEvents

Properties

protected array $dispatchesEvents The event map.
protected array $observables User exposed observable events.
static Dispatcher $dispatcher Event dispatcher instance
static protected array $traitInitializers The array of trait initializers that will be called on each new instance.
static protected array $booted The array of booted instances.

Methods

void
bootIfNotBooted()

Check if we needs to be booted and if so, do it.

static void
boot()

Bootstrap traits.

static void
bootTraits()

Boot all of the bootable traits.

void
initializeTraits()

Initialize any initializable traits.

static void
observe(object|array|string $classes)

Register observers.

void
registerObserver(object|string $class)

Register a single observer.

array
getObservableEvents()

Get the observable event names.

$this
setObservableEvents(array $observables)

Set the observable event names.

void
addObservableEvents(array|mixed $observables)

Add an observable event name.

void
removeObservableEvents(array|mixed $observables)

Remove an observable event name.

static void
registerEvent(string $event, Closure|string $callback)

Register a event with the dispatcher.

mixed
fireEvent(string $event, bool $halt = true)

Fire the given event.

mixed|null
fireCustomEvent(string $event, string $method)

Fire a custom event for the given event.

mixed
filterEventResults(mixed $result)

Filter the event results.

static void
flushEventListeners()

Remove all of the event listeners.

static Dispatcher
getEventDispatcher()

Get the event dispatcher instance.

static void
setEventDispatcher(Dispatcher $dispatcher)

Set the event dispatcher instance.

static void
unsetEventDispatcher()

Unset the event dispatcher.

static mixed
withoutEvents(callable $callback)

Execute a callback without firing any events.

Details

at line 56
protected void bootIfNotBooted()

Check if we needs to be booted and if so, do it.

Return Value

void

at line 73
static protected void boot()

Bootstrap traits.

Return Value

void

at line 83
static protected void bootTraits()

Boot all of the bootable traits.

Return Value

void

at line 108
protected void initializeTraits()

Initialize any initializable traits.

Return Value

void

at line 123
static void observe(object|array|string $classes)

Register observers.

Parameters

object|array|string $classes

Return Value

void

Exceptions

RuntimeException

at line 140
protected void registerObserver(object|string $class)

Register a single observer.

Parameters

object|string $class

Return Value

void

Exceptions

RuntimeException

at line 180
array getObservableEvents()

Get the observable event names.

Return Value

array

at line 197
$this setObservableEvents(array $observables)

Set the observable event names.

Parameters

array $observables

Return Value

$this

at line 210
void addObservableEvents(array|mixed $observables)

Add an observable event name.

Parameters

array|mixed $observables

Return Value

void

at line 224
void removeObservableEvents(array|mixed $observables)

Remove an observable event name.

Parameters

array|mixed $observables

Return Value

void

at line 239
static protected void registerEvent(string $event, Closure|string $callback)

Register a event with the dispatcher.

Parameters

string $event
Closure|string $callback

Return Value

void

at line 255
protected mixed fireEvent(string $event, bool $halt = true)

Fire the given event.

Parameters

string $event
bool $halt

Return Value

mixed

at line 287
protected mixed|null fireCustomEvent(string $event, string $method)

Fire a custom event for the given event.

Parameters

string $event
string $method

Return Value

mixed|null

at line 306
protected mixed filterEventResults(mixed $result)

Filter the event results.

Parameters

mixed $result

Return Value

mixed

at line 322
static void flushEventListeners()

Remove all of the event listeners.

Return Value

void

at line 344
static Dispatcher getEventDispatcher()

Get the event dispatcher instance.

Return Value

Dispatcher

at line 355
static void setEventDispatcher(Dispatcher $dispatcher)

Set the event dispatcher instance.

Parameters

Dispatcher $dispatcher

Return Value

void

at line 365
static void unsetEventDispatcher()

Unset the event dispatcher.

Return Value

void

at line 376
static mixed withoutEvents(callable $callback)

Execute a callback without firing any events.

Parameters

callable $callback

Return Value

mixed