\QuickApps\EventEventDispatcher

Provides trigger() method for dispatching events.

Summary

Methods
Properties
Constants
__construct()
eventManager()
instance()
trigger()
triggerArray()
triggered()
No public properties found
No constants found
_prepareEvent()
_log()
$_instances
$_log
$_eventManager
N/A
No private methods found
No private properties found
N/A

Properties

$_instances

$_instances : array

Holds a list of all instances.

Type

array

$_log

$_log : array

Holds a list of all the events that were fired.

Type

array

$_eventManager

$_eventManager : \Cake\Event\EventManager

EventManager used by this instance.

Type

\Cake\Event\EventManager

Methods

__construct()

__construct()

Constructor.

eventManager()

eventManager(\Cake\Event\EventManager|null $eventManager) : \Cake\Event\EventManager

Gets or sets event manager instance associated to this dispatcher.

Parameters

\Cake\Event\EventManager|null $eventManager

The instance to set

Returns

\Cake\Event\EventManager

instance()

instance(string $name) : \QuickApps\Event\EventDispatcher

Gets an instance of this class.

Parameters

string $name

Name of the Event Dispatcher instance to get, if does not exists a new instance will be created and registered

Returns

\QuickApps\Event\EventDispatcher

trigger()

trigger(array|string $eventName) : \Cake\Event\Event

Trigger the given event name.

Usage:

EventDispatcher::instance()->trigger('GetTime', $arg0, $arg1, ..., $argn);

Your Event Listener must implement:

public function implementedEvents()
{
    return ['GetTime' => 'handlerForGetTime'];
}

public function handlerForGetTime(Event $event, $arg0, $arg1, ..., $argn)
{
    // logic
}

You can provide a subject to use by passing an array as first arguments where the first element is the event name and the second one is the subject:

EventDispatcher::instance()
    ->trigger(['GetTime', new MySubject()], $arg0, $arg1, ..., $argn);

If no subject is given an instance of "EventDispatcher" class will be used by default.

Parameters

array|string $eventName

The event name to trigger

Returns

\Cake\Event\Event —

The event object that was triggered

triggerArray()

triggerArray(array|string $eventName, array $data) : \Cake\Event\Event

Similar to "trigger()" but this method expects that data is given as an associative array instead of function arguments.

Usage:

EventDispatcher::instance()->triggerArray('myEvent', [$data1, $data2]);

Which is equivalent to:

EventDispatcher::instance()->trigger('myEvent', $data1, $data2);

Parameters

array|string $eventName

The event name to trigger

array $data

Information to be passed to event listener

Returns

\Cake\Event\Event —

The event object that was triggered

triggered()

triggered(string|null $eventName, boolean $sort) : integer|array

Retrieve the number of times an event was triggered, or the complete list of events that were triggered.

Parameters

string|null $eventName

The name of the event, if null returns the entire list of event that were fired

boolean $sort

If first argument is null set this to true to sort the list. Defaults to true

Returns

integer|array

_prepareEvent()

_prepareEvent(array|string $eventName, array $data) : \Cake\Event\Event

Prepares the event object to be triggered.

Parameters

array|string $eventName

The event name to trigger

array $data

Data to be passed to event listener method

Returns

\Cake\Event\Event

_log()

_log(string $eventName) : void

Logs the given event.

Parameters

string $eventName

The event name to log