Interface EventManagerInterface
Interface EventManagerInterface
Direct Implementers
Method Summary
- dispatch() publicDispatches a new event to all configured listeners
- listeners() publicReturns a list of all listeners for an eventKey in the order they should be called
- off() publicRemove a listener from the active listeners.
- on() publicAdds a new listener to an event.
Method Detail
dispatch()source public
dispatch( string|Cake\Event\EventInterface $event )
Dispatches a new event to all configured listeners
Parameters
- string|
Cake\Event\EventInterface
$event
- The event key name or instance of EventInterface.
Returns
Cake\Event\EventInterface
Triggers
$eventlisteners()source 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
arrayoff()source public
off( string|Cake\Event\EventListenerInterface $eventKey , callable|null $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);
Parameters
- string|
Cake\Event\EventListenerInterface
$eventKey
The event unique identifier name with which the callback has been associated, or the $listener you want to remove.
- callable|null
$callable
optional null - The callback you want to detach.
Returns
$this
on()source public
on( string|Cake\Event\EventListenerInterface|null $eventKey = null , array|callable $options = [] , callable|null $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);
Parameters
- string|
Cake\Event\EventListenerInterface
|null$eventKey
optional null The event unique identifier name with which the callback will be associated. If $eventKey is an instance of Cake\Event\EventListenerInterface its events will be bound using the
implementedEvents
methods.- array|callable
$options
optional [] Either an array of options or the callable you wish to bind to $eventKey. If an array of options, the
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|null
$callable
optional null - The callable function you want invoked.
Returns
$this
Throws
InvalidArgumentExceptionWhen event key is missing or callable is not an instance of Cake\Event\EventListenerInterface.
© 2005–present 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.
https://api.cakephp.org/3.7/class-Cake.Event.EventManagerInterface.html