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.
Copyright: Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
License: MIT License
Location: Cake/Event/CakeEventManager.php
Properties summary
-
$_generalManager
protected staticThe globally available instance, used for dispatching events attached from any scope -
$_isGlobal
protectedboolean
Internal flag to distinguish a common manager from the singleton -
$_listeners
protectedobject
List of listener callbacks associated to -
$defaultPriority
public staticinteger
The default priority queue value for new, attached listeners
Method Summary
-
_attachSubscriber() protected
Auxiliary function to attach all implemented callbacks of a CakeEventListener class instance as individual methods on this manager
-
_detachSubscriber() protected
Auxiliary function to help detach all listeners provided by an object implementing CakeEventListener -
_extractCallable() protected
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 -
attach() public
Adds a new listener to an event. Listeners -
detach() public
Removes a listener from the active listeners. -
dispatch() public
Dispatches a new event to all configured listeners -
instance() public static
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
-
listeners() public
Returns a list of all listeners for an eventKey in the order they should be called
Method Detail
_attachSubscriber() 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
_detachSubscriber() 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
_extractCallable() 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
attach() 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
andpassParams
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
When event key is missing or callable is not an instance of CakeEventListener.
detach() 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
dispatch() 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
instance() 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
Returns
listeners() public ¶
listeners( string $eventKey )
Returns a list of all listeners for an eventKey in the order they should be called
Parameters
- string $eventKey
Returns
Properties detail
$_generalManager ¶
The globally available instance, used for dispatching events attached from any scope
null
$_isGlobal ¶
Internal flag to distinguish a common manager from the singleton
false
$defaultPriority ¶
The default priority queue value for new, attached listeners
10