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.
Cake\Event\EventList|nullThe event list object.
Cake\Event\EventManager|nullThe globally available instance, used for dispatching events attached from any scope
boolInternal flag to distinguish a common manager from the singleton
arrayList of listener callbacks associated to
boolEnables automatic adding of events to the event list object if it is present.
intThe default priority queue value for new, attached listeners
Debug friendly object properties.
Auxiliary function to attach all implemented callbacks of a Cake\Event\EventListenerInterface class instance as individual methods on this manager
Calls a listener.
Auxiliary function to help detach all listeners provided by an object implementing EventListenerInterface
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 {@link \Cake\Event\EventListenerInterface}
Adds an event to the list if the event list object is present.
Dispatches a new event to all configured listeners
Returns the event list.
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
Returns whether this manager is set up to track events
Returns a list of all listeners for an eventKey in the order they should be called
Returns the listeners matching a specified pattern
Remove a listener from the active listeners.
Adds a new listener to an event.
Returns the listeners for the specified event key indexed by priority
Enables the listing of dispatched events.
Enables / disables event tracking at runtime.
Disables the listing of dispatched events.
__debugInfo(): array<string, mixed>
Debug friendly object properties.
array<string, mixed>_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.
void_callListener(callable $listener, Cake\Event\EventInterface $event): mixed
Calls a listener.
callable $listener The listener to trigger.
Cake\Event\EventInterface $event Event instance.
mixed_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 optional event key name to unsubscribe the listener from
void_extractCallable(array $function, Cake\Event\EventListenerInterface $object): array
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 {@link \Cake\Event\EventListenerInterface}
array $function the array taken from a handler definition for an event
Cake\Event\EventListenerInterface $object The handler object
arrayaddEventToList(Cake\Event\EventInterface $event): $this
Adds an event to the list if the event list object is present.
Cake\Event\EventInterface $event An event to add to the list.
$thisdispatch(Cake\Event\EventInterface|string $event): Cake\Event\EventInterface
Dispatches a new event to all configured listeners
Cake\Event\EventInterface|string $event Cake\Event\EventInterfacegetEventList(): Cake\Event\EventList|null
Returns the event list.
Cake\Event\EventList|nullinstance(Cake\Event\EventManager|null $manager = null): Cake\Event\EventManager
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 optional Event manager instance.
Cake\Event\EventManagerisTrackingEvents(): bool
Returns whether this manager is set up to track events
boollisteners(string $eventKey): array
Returns a list of all listeners for an eventKey in the order they should be called
string $eventKey arraymatchingListeners(string $eventKeyPattern): array
Returns the listeners matching a specified pattern
string $eventKeyPattern Pattern to match.
arrayoff(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);
Cake\Event\EventListenerInterface|callable|string $eventKey Cake\Event\EventListenerInterface|callable|null $callable optional $thison(Cake\Event\EventListenerInterface|string $eventKey, callable|array $options = [], 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); Cake\Event\EventListenerInterface|string $eventKey callable|array $options optional callable|null $callable optional $thisprioritisedListeners(string $eventKey): array
Returns the listeners for the specified event key indexed by priority
string $eventKey Event key.
arraysetEventList(Cake\Event\EventList $eventList): $this
Enables the listing of dispatched events.
Cake\Event\EventList $eventList The event list object to use.
$thistrackEvents(bool $enabled): $this
Enables / disables event tracking at runtime.
bool $enabled True or false to enable / disable it.
$thisunsetEventList(): $this
Disables the listing of dispatched events.
$thisThe event list object.
Cake\Event\EventList|nullThe globally available instance, used for dispatching events attached from any scope
Cake\Event\EventManager|nullInternal flag to distinguish a common manager from the singleton
boolList of listener callbacks associated to
arrayEnables automatic adding of events to the event list object if it is present.
boolThe default priority queue value for new, attached listeners
int
© 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/4.4/class-Cake.Event.EventManager.html