Emitter

Adds event related features to any class.

 trait Winter\Storm\Support\Traits\Emitter

Properties

protected $emitterEventCollection : array

Collection of registered events.

protected $emitterEventSorted : array

Sorted collection of events.

protected $emitterSingleEventCollection : array

Collection of registered events to be fired once only.

Methods

public bindEvent (string | Closure | QueuedClosure $event, mixed $callback = null, integer $priority) : self

Create a new event binding.

Parameters
Property Description
$event
string | Closure | QueuedClosure
$callback
mixed

when the third parameter is omitted and a Closure or QueuedClosure is provided this parameter is used as an integer this is used as priority variable

$priority
integer
Returns
self

public bindEventOnce (string | Closure | QueuedClosure $event, QueuedClosure | Closure | null $callback = null) : self

Create a new event binding that fires once only

Parameters
Property Description
$event
string | Closure | QueuedClosure
$callback
QueuedClosure | Closure | null

When a Closure or QueuedClosure is provided as the first parameter this parameter can be omitted

Returns
self

public fireEvent (string $event, array $params = [], boolean $halt = false) : array | mixed | null

Fire an event and call the listeners.

Parameters
Property Description
$event
string

Event name

$params
array

Event parameters

$halt
boolean

Halt after first non-null result

Returns
array | mixed | null

If halted, the first non-null result. If not halted, an array of event results. Returns null if no listeners returned a result.

public unbindEvent (string | array | object $event = null) : self

Destroys an event binding.

Parameters
Property Description
$event
string | array | object

Event to destroy

Returns
self

protected emitterEventSortEvents (string $eventName) : void

Sort the listeners for a given event by priority.

Parameters
Property Description
$eventName
string
Returns
void

protected parseEventAndPayload (mixed $event, mixed $payload = null) : array

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

Parameters
Property Description
$event
mixed
$payload
mixed
Returns
array
Copyright © 2024 Winter CMS