System\Traits\EventEmitter

Overview

EventEmitter adds system event related features to any class.


Protected Properties

protected array $emitterSingleEventCollection

emitterSingleEventCollection of events to be fired once only

protected array $emitterEventCollection

emitterEventCollection of all registered events

protected array $emitterEventSorted

emitterEventSorted collection


Public Methods

public bindEvent()

public bindEvent($event, $callback, $priority = 0): void 

bindEvent creates a new event binding

public bindEventOnce()

public bindEventOnce($event, $callback, $priority = 0): void 

bindEventOnce creates a new event binding that fires once only

public fireEvent()

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

fireEvent and call the listeners

public fireSystemEvent()

public fireSystemEvent(
    string $event,
    array $params = [],
    boolean $halt = true
): mixed 

fireSystemEvent fires a combination of local and global events. The first segment is removed from the event name locally and the local object is passed as the first argument to the event globally. Halting is also enabled by default.

For example:

$this->fireSystemEvent('backend.list.myEvent', ['my value']);

Is equivalent to:

$this->fireEvent('list.myEvent', ['myvalue'], true);

Event::fire('backend.list.myEvent', [$this, 'myvalue'], true);

public fireViewEvent()

public fireViewEvent(string $event, array $params = []): string 

fireViewEvent is a special event function used for extending within view files, allowing HTML to be injected multiple times.

For example:

<?= $this->fireViewEvent('backend.auth.extendSigninView') ?>

public unbindEvent()

public unbindEvent($event = null): void 

unbindEvent destroys an event binding

Protected Methods

protected emitterEventSortEvents()

protected emitterEventSortEvents($eventName, $combined = []): array 

emitterEventSortEvents sorts the listeners for a given event by priority