Interface EventManagerInterface
Interface EventManagerInterface
Method Summary
-
dispatch() public
Dispatches a new event to all configured listeners
-
listeners() public
Returns a list of all listeners for an eventKey in the order they should be called
-
off() public
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); -
on() public
Adds a new listener to an event.
Binding an EventListenerInterface:
$eventManager->on($listener);Binding with no options:
$eventManager->on('Model.beforeSave', $callable);Binding with options:
$eventManager->on('Model.beforeSave', $callable, ['priority' => 90]);
Method Detail
dispatch() ¶ public
dispatch(Cake\Event\EventInterface<TSubject>|string $event): $event is string ? \Cake\Event\EventInterface<object> : \Cake\Event\EventInterface<TSubject>
Dispatches a new event to all configured listeners
Templates
TSubject
of object Parameters
-
Cake\Event\EventInterface<TSubject>|string$event The event key name or instance of EventInterface.
Returns
$event is string ? \Cake\Event\EventInterface<object> : \Cake\Event\EventInterface<TSubject>listeners() ¶ public
listeners(string $eventKey): array
Returns a list of all listeners for an eventKey in the order they should be called
Parameters
-
string$eventKey Event key.
Returns
arrayoff() ¶ public
off(Cake\Event\EventListenerInterface|callable|string $eventKey, Cake\Event\EventListenerInterface|callable|null $callable = null): $this
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
-
Cake\Event\EventListenerInterface|callable|string$eventKey The event unique identifier name with which the callback has been associated, or the $listener you want to remove.
-
Cake\Event\EventListenerInterface|callable|null$callable optional The callback you want to detach.
Returns
$thison() ¶ public
on(Cake\Event\EventListenerInterface|string $eventKey, callable|null $callable = null, array $options = []): $this
Adds a new listener to an event.
Binding an EventListenerInterface:
$eventManager->on($listener);
Binding with no options:
$eventManager->on('Model.beforeSave', $callable);
Binding with options:
$eventManager->on('Model.beforeSave', $callable, ['priority' => 90]);
Parameters
-
Cake\Event\EventListenerInterface|string$eventKey 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.-
callable|null$callable optional The callable function you want invoked.
-
array$options optional An array of options, the
prioritykey 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.
Returns
$thisThrows
InvalidArgumentExceptionWhen event key is missing or callable is not an instance of Cake\Event\EventListenerInterface.