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.
_attachSubscriber( Cake\Event\EventListenerInterface $subscriber )
Auxiliary function to attach all implemented callbacks of a Cake\Event\EventListenerInterface class instance as individual methods on this manager
Cake\Event\EventListenerInterface
$subscriber
_callListener( callable $listener , Cake\Event\Event $event )
Calls a listener.
Direct callback invocation is up to 30% faster than using call_user_func_array. Optimize the common cases to provide improved performance.
$listener
Cake\Event\Event
$event
mixed
_detachSubscriber( Cake\Event\EventListenerInterface $subscriber , string|null $eventKey null )
Auxiliary function to help detach all listeners provided by an object implementing EventListenerInterface
Cake\Event\EventListenerInterface
$subscriber
$eventKey
optional null _extractCallable( array $function , Cake\Event\EventListenerInterface $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 Cake\Event\EventListenerInterface
$function
Cake\Event\EventListenerInterface
$object
callable
attach( callable|Cake\Event\EventListenerInterface $callable , string $eventKey null , array $options [] )
Adds a new listener to an event.
Cake\Event\EventListenerInterface
$callable
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
optional null $options
optional [] priority
flag to the listener. In the future more options may be added. Priorities are treated as queues. Lower values are called before higher ones, and multiple attachments added to the same priority queue will be treated in the order of insertion.InvalidArgumentException
detach( callable|Cake\Event\EventListenerInterface $callable , string|null $eventKey null )
Removes a listener from the active listeners.
Cake\Event\EventListenerInterface
$callable
$eventKey
optional null dispatch( string|Cake\Event\Event $event )
Dispatches a new event to all configured listeners
Cake\Event\Event
$event
Cake\Event\Event
instance( Cake\Event\EventManager $manager null )
Returns the globally available instance of a Cake\Event\EventManager 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
Cake\Event\EventManager
$manager
optional null Cake\Event\EventManager
listeners( string $eventKey )
Returns a list of all listeners for an eventKey in the order they should be called
$eventKey
array
off( string|Cake\Event\EventListenerInterface $eventKey , callable $callable null )
Remove a listener from the active listeners.
Remove a EventListenerInterface entirely:
$manager->off($listener);
Remove all listeners for a given event:
$manager->off('My.event');
Remove a specific listener:
$manager->off('My.event', $callback);
Remove a callback from all events:
$manager->off($callback);
Cake\Event\EventListenerInterface
$eventKey
$callable
optional null on( string|Cake\Event\EventListenerInterface $eventKey null , array|callable $options [] , callable $callable null )
Adds a new listener to an event.
A variadic interface to add listeners that emulates jQuery.on().
Binding an EventListenerInterface:
$eventManager->on($listener);
Binding with no options:
$eventManager->on('Model.beforeSave', $callable);
Binding with options:
$eventManager->on('Model.beforeSave', ['priority' => 90], $callable);
Cake\Event\EventListenerInterface
$eventKey
optional null implementedEvents
methods.$options
optional [] priority
key can be used to define the order. Priorities are treated as queues. Lower values are called before higher ones, and multiple attachments added to the same priority queue will be treated in the order of insertion.$callable
optional null InvalidArgumentException
prioritisedListeners( string $eventKey )
Returns the listeners for the specified event key indexed by priority
$eventKey
array
© 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/3.1/class-Cake.Event.EventManager.html