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.
$_eventList protected Cake\Event\EventList|null$_isGlobal protected boolean$_listeners protected array$_trackEvents protected booleanintegerAuxiliary function to attach all implemented callbacks of a Cake\Event\EventListenerInterface class instance as individual methods on this manager
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
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
_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.
$listener Cake\Event\Event $event _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 addEventToList( Cake\Event\Event $event )
Adds an event to the list if the event list object is present.
Cake\Event\Event $event attach( callable|Cake\Event\EventListenerInterface $callable , string|null $eventKey = null , array $options = [] )
Adds a new listener to an event.
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 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 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
$options optional [] used to set the 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.
When event key is missing or callable is not an instance of Cake\Event\EventListenerInterface.
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\EventInterface $event )
Dispatches a new event to all configured listeners
Cake\Event\EventInterface $event Cake\Event\EventInterfaceCake\Event\EventManagerInterface::dispatch() instance( Cake\Event\EventManager|null $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|null $manager optional null Cake\Event\EventManagerisTrackingEvents( )
Returns whether this manager is set up to track events
listeners( string $eventKey )
Returns a list of all listeners for an eventKey in the order they should be called
$eventKey Cake\Event\EventManagerInterface::listeners() matchingListeners( string $eventKeyPattern )
Returns the listeners matching a specified pattern
$eventKeyPattern off( string|Cake\Event\EventListenerInterface $eventKey , callable|null $callable = null )
Remove a listener from the active listeners.
Cake\Event\EventListenerInterface $eventKey The event unique identifier name with which the callback has been associated, or the $listener you want to remove.
$callable optional null Cake\Event\EventManagerInterface::off() on( string|Cake\Event\EventListenerInterface|null $eventKey = null , array|callable $options = [] , callable|null $callable = null )
Adds a new listener to an event.
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.
$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 optional null When event key is missing or callable is not an instance of Cake\Event\EventListenerInterface.
Cake\Event\EventManagerInterface::on() prioritisedListeners( string $eventKey )
Returns the listeners for the specified event key indexed by priority
$eventKey setEventList( Cake\Event\EventList $eventList )
Enables the listing of dispatched events.
Cake\Event\EventList $eventList trackEvents( boolean $enabled )
Enables / disables event tracking at runtime.
$enabled unsetEventList( )
Disables the listing of dispatched events.
protected static Cake\Event\EventManager
The globally available instance, used for dispatching events attached from any scope
protected boolean
Internal flag to distinguish a common manager from the singleton
false
protected boolean
Enables automatic adding of events to the event list object if it is present.
false
public static integer
The default priority queue value for new, attached listeners
10
© 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.8/class-Cake.Event.EventManager.html