$defaultPriority
$defaultPriority : integer
The default priority queue value for new, attached listeners
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.
$_generalManager : \Cake\Event\EventManager
The globally available instance, used for dispatching events attached from any scope
$_eventList : \Cake\Event\EventList|null
The event list object.
instance(\Cake\Event\EventManager|null $manager = null) : static
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|null | $manager | Event manager instance. |
The global event manager
attach(callable|\Cake\Event\EventListenerInterface $callable, string|null $eventKey = null, array $options = array()) : void
Adds a new listener to an event.
callable|\Cake\Event\EventListenerInterface | $callable | PHP valid callback type or instance of Cake\Event\EventListenerInterface to be called
when the event named with $eventKey is triggered. If a Cake\Event\EventListenerInterface instance is passed, then the |
string|null | $eventKey | The event unique identifier name with which the callback will be associated. If $callable is an instance of Cake\Event\EventListenerInterface this argument will be ignored |
array | $options | used to set the |
When event key is missing or callable is not an instance of Cake\Event\EventListenerInterface.
on(string|\Cake\Event\EventListenerInterface|null $eventKey = null, array|callable $options = array(), callable|null $callable = null) : $this
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);
string|\Cake\Event\EventListenerInterface|null | $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 |
array|callable | $options | Either an array of options or the callable you wish to
bind to $eventKey. If an array of options, the |
callable|null | $callable | The callable function you want invoked. |
None found |
detach(callable|\Cake\Event\EventListenerInterface $callable, string|null $eventKey = null) : void
Removes a listener from the active listeners.
callable|\Cake\Event\EventListenerInterface | $callable | any valid PHP callback type or an instance of EventListenerInterface |
string|null | $eventKey | The event unique identifier name with which the callback has been associated |
None found |
off(string|\Cake\Event\EventListenerInterface $eventKey, 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);
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 | The callback you want to detach. |
None found |
dispatch(string|\Cake\Event\EventInterface $event) : \Cake\Event\EventInterface
Dispatches a new event to all configured listeners
string|\Cake\Event\EventInterface | $event | The event key name or instance of EventInterface. |
None found |
listeners(string $eventKey) : array
Returns a list of all listeners for an eventKey in the order they should be called
string | $eventKey | Event key. |
None found |
prioritisedListeners(string $eventKey) : array
Returns the listeners for the specified event key indexed by priority
string | $eventKey | Event key. |
None found |
matchingListeners(string $eventKeyPattern) : array
Returns the listeners matching a specified pattern
string | $eventKeyPattern | Pattern to match. |
None found |
getEventList() : \Cake\Event\EventList
Returns the event list.
None found |
addEventToList(\Cake\Event\Event $event) : $this
Adds an event to the list if the event list object is present.
\Cake\Event\Event | $event | An event to add to the list. |
None found |
trackEvents(boolean $enabled) : $this
Enables / disables event tracking at runtime.
boolean | $enabled | True or false to enable / disable it. |
None found |
isTrackingEvents() : boolean
Returns whether this manager is set up to track events
None found |
setEventList(\Cake\Event\EventList $eventList) : $this
Enables the listing of dispatched events.
\Cake\Event\EventList | $eventList | The event list object to use. |
None found |
None found |
None found |
_attachSubscriber(\Cake\Event\EventListenerInterface $subscriber) : void
Auxiliary function to attach all implemented callbacks of a Cake\Event\EventListenerInterface class instance as individual methods on this manager
\Cake\Event\EventListenerInterface | $subscriber | Event listener. |
None found |
_extractCallable(array $function, \Cake\Event\EventListenerInterface $object) : callable
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
array | $function | the array taken from a handler definition for an event |
\Cake\Event\EventListenerInterface | $object | The handler object |
None found |
_detachSubscriber(\Cake\Event\EventListenerInterface $subscriber, string|null $eventKey = null) : void
Auxiliary function to help detach all listeners provided by an object implementing EventListenerInterface
\Cake\Event\EventListenerInterface | $subscriber | the subscriber to be detached |
string|null | $eventKey | optional event key name to unsubscribe the listener from |
None found |
_callListener(callable $listener, \Cake\Event\Event $event) : mixed
Calls a listener.
callable | $listener | The listener to trigger. |
\Cake\Event\Event | $event | Event instance. |
The result of the $listener function.
None found |