The event manager is responsible for keeping track of event listeners, passing the correct data to them, and firing them in the correct order, when associated events are triggered. You can create multiple instances of this object to manage local events or keep a single instance and pass it around to manage all events in your app.

package Cake.Event

 Methods

Adds a new listener to an event. Listeners

attach(callback|\CakeEventListener $callable, string $eventKey = null, array $options = array()) : void

Parameters

$callable

callback\CakeEventListener

PHP valid callback type or instance of CakeEventListener to be called when the event named with $eventKey is triggered. If a CakeEventListener instance is passed, then the implementedEvents method will be called on the object to register the declared events individually as methods to be managed by this class. It is possible to define multiple event handlers per event name.

$eventKey

string

The event unique identifier name with which the callback will be associated. If $callable is an instance of CakeEventListener this argument will be ignored

$options

array

used to set the priority and passParams flags to the listener. Priorities are handled like queues, and multiple attachments added to the same priority queue will be treated in the order of insertion. passParams means that the event data property will be converted to function arguments when the listener is called. If $called is an instance of CakeEventListener, this parameter will be ignored

Exceptions

\InvalidArgumentException When event key is missing or callable is not an instance of CakeEventListener.

Removes a listener from the active listeners.

detach(callback|\CakeEventListener $callable, string $eventKey = null) : void

Parameters

$callable

callback\CakeEventListener

any valid PHP callback type or an instance of CakeEventListener

$eventKey

string

The event unique identifier name with which the callback has been associated

Dispatches a new event to all configured listeners

dispatch(string|\CakeEvent $event) : \CakeEvent
triggers $event

Parameters

$event

string\CakeEvent

the event key name or instance of CakeEvent

Returns

\CakeEvent

Returns the globally available instance of a CakeEventManager this is used for dispatching events attached from outside the scope other managers were created. Usually for creating hook systems or inter-class communication

instance(\CakeEventManager $manager = null) : \CakeEventManager
Static
If called with the first parameter, it will be set as the globally available instance

Parameters

$manager

\CakeEventManager

Returns

\CakeEventManagerthe global event manager

Returns a list of all listeners for an eventKey in the order they should be called

listeners(string $eventKey) : array

Parameters

$eventKey

string

Returns

array

Returns the listeners for the specified event key indexed by priority

prioritisedListeners(string $eventKey) : array

Parameters

$eventKey

string

Returns

array

Auxiliary function to attach all implemented callbacks of a CakeEventListener class instance as individual methods on this manager

_attachSubscriber(\CakeEventListener $subscriber) : void

Parameters

$subscriber

\CakeEventListener

Auxiliary function to help detach all listeners provided by an object implementing CakeEventListener

_detachSubscriber(\CakeEventListener $subscriber, string $eventKey = null) : void

Parameters

$subscriber

\CakeEventListener

the subscriber to be detached

$eventKey

string

optional event key name to unsubscribe the listener from

Auxiliary function to extract and return a PHP callback type out of the callable definition from the return value of the `implementedEvents` method on a CakeEventListener

_extractCallable(array $function, \CakeEventListener $object) : callback

Parameters

$function

array

the array taken from a handler definition for an event

$object

\CakeEventListener

The handler object

Returns

callback

 Properties

 

The default priority queue value for new, attached listeners

$defaultPriority : integer

Default

10
Static
 

The globally available instance, used for dispatching events attached from any scope

$_generalManager : \CakeEventManager

Default

null
Static
 

Internal flag to distinguish a common manager from the singleton

$_isGlobal : boolean

Default

false
 

List of listener callbacks associated to

$_listeners : object

Default

array()