API Documentation for: 1.0.1
Show:

EventDispatcher Class

Namespace: Canteen\Events

Basic EventDispatcher adapated from Symphony's EventDispatcher but simplified to mirror the Canteen Client dispatcher API.

Item Index

Properties

Methods

getListeners

(
  • [eventType=null]
)
Array private

Gets the listeners of a specific event or all listeners.

Parameters:

  • [eventType=null] String optional

    The type of the event

Returns:

Array:

The event listeners for the specified event, or all event listeners by event name

has

(
  • eventType
)
Boolean

Checks whether an event has any registered listeners.

Parameters:

  • eventType String

    The name of the event

Returns:

Boolean:

true if the specified event has any listeners, false otherwise

off

(
  • eventType
  • [listener=null]
)
EventDispatcher

Removes an event listener from the specified events.

Parameters:

  • eventType String | Array

    The event(s) to remove a listener from

  • [listener=null] Callable optional

    The listener to remove, if not specified removes all listeners with matching event type

Returns:

EventDispatcher:

Reference reference of this for chaining

on

(
  • eventType
  • listener
  • [priority=0]
)
EventDispatcher

Adds an event listener that listens on the specified events.

Parameters:

  • eventType String | Array

    The event to listen on or collection of events

  • listener Callable

    The listener

  • [priority=0] Int optional

    The higher this value, the earlier an event listener will be triggered in the chain

Returns:

EventDispatcher:

Reference reference of this for chaining

sortListeners

(
  • eventType
)
private

Sorts the internal list of listeners for the given event by priority.

Parameters:

  • eventType String

    The name of the event.

trigger

(
  • event
)
Event

Dispatches an event to all registered listeners.

Parameters:

  • event String | Event

    The name of the event to dispatch or the Event object. The name of the event is the name of the method that is invoked on listeners.

Returns:

Properties

listeners

Array private

The collection of listeners

sorted

Array private

The collection of sorted listeners