System\Traits\EventEmitter

Source: ~/modules/system/traits/EventEmitter.php

Adds system event related features to any class.

Protected properties

protected array $emitterSingleEventCollection

Collection of registered events to be fired once only.

protected array $emitterEventCollection

Collection of registered events.

protected array $emitterEventSorted

Sorted collection of events.

Public methods

public self bindEvent($event, $callback, $priority=0)

Create a new event binding.

Parameters
  • $event
  • $callback
  • $priority

public self bindEventOnce($event, $callback)

Create a new event binding that fires once only

Parameters
  • $event
  • $callback

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

Fire an event and call the listeners.

Parameters
  • string $event - Event name
  • array $params - Event parameters
  • boolean $halt - Halt after first non-null result

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

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);
Parameters
  • string $event - Event name
  • array $params - Event parameters
  • boolean $halt - Halt after first non-null result

public string fireViewEvent(string $event, array $params=array())

Special event function used for extending within view files, allowing HTML to be injected multiple times.

For example:

<?= $this->fireViewEvent('backend.auth.extendSigninView') ?>
Parameters
  • string $event - Event name
  • array $params - Event parameters

public self unbindEvent(string $event=NULL)

Destroys an event binding.

Parameters
  • string $event - Event to destroy

Protected methods

protected array emitterEventSortEvents(string $eventName)

Sort the listeners for a given event by priority.

Parameters
  • string $eventName