Class CakeEventManager

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
Copyright: Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
License: MIT License
Located at Cake/Event/CakeEventManager.php

Method Detail

_attachSubscribersource protected

_attachSubscriber( CakeEventListener $subscriber )

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

Parameters

CakeEventListener $subscriber
Event listener.

_detachSubscribersource protected

_detachSubscriber( CakeEventListener $subscriber , string $eventKey null )

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

Parameters

CakeEventListener $subscriber
the subscriber to be detached
string $eventKey optional null
optional event key name to unsubscribe the listener from

_extractCallablesource protected

_extractCallable( array $function , CakeEventListener $object )

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

Parameters

array $function
the array taken from a handler definition for an event
CakeEventListener $object
The handler object

Returns

callable
callback

attachsource public

attach( callable|CakeEventListener $callable , string $eventKey null , array $options array() )

Adds a new listener to an event. Listeners

Parameters

callable|CakeEventListener $callable
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.
string $eventKey optional null
The event unique identifier name with which the callback will be associated. If $callable is an instance of CakeEventListener this argument will be ignored
array $options optional 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

Throws

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

detachsource public

detach( callable|CakeEventListener $callable , string $eventKey null )

Removes a listener from the active listeners.

Parameters

callable|CakeEventListener $callable
any valid PHP callback type or an instance of CakeEventListener
string $eventKey optional null
The event unique identifier name with which the callback has been associated

dispatchsource public

dispatch( string|CakeEvent $event )

Dispatches a new event to all configured listeners

Parameters

string|CakeEvent $event
the event key name or instance of CakeEvent

Returns

CakeEvent
CakeEvent

Triggers

$event

instancesource public static

instance( CakeEventManager $manager null )

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

If called with the first parameter, it will be set as the globally available instance

Parameters

CakeEventManager $manager optional null
Optional event manager instance.

Returns

CakeEventManager
the global event manager

listenerssource public

listeners( string $eventKey )

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

Parameters

string $eventKey
Event key.

Returns

array
array

prioritisedListenerssource public

prioritisedListeners( string $eventKey )

Returns the listeners for the specified event key indexed by priority

Parameters

string $eventKey
Event key.

Returns

array
array

Properties summary

$_generalManagersource

protected static CakeEventManager

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

null

$_isGlobalsource

protected boolean

Internal flag to distinguish a common manager from the singleton

false

$_listenerssource

protected object

List of listener callbacks associated to

array()

$defaultPrioritysource

public static integer

The default priority queue value for new, attached listeners

10

© 2005–2016 The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
http://api.cakephp.org/2.7/class-CakeEventManager.html