CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Team
    • Issues (Github)
    • YouTube Channel
    • Get Involved
    • Bakery
    • Featured Resources
    • Newsletter
    • Certification
    • My CakePHP
    • CakeFest
    • Facebook
    • Twitter
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 3.8 Red Velvet API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 3.8
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Cake
    • Auth
      • Storage
    • Cache
      • Engine
    • Collection
      • Iterator
    • Command
    • Console
      • Exception
    • Controller
      • Component
      • Exception
    • Core
      • Configure
        • Engine
      • Exception
      • Retry
    • Database
      • Driver
      • Exception
      • Expression
      • Schema
      • Statement
      • Type
    • Datasource
      • Exception
    • Error
      • Middleware
    • Event
      • Decorator
    • Filesystem
    • Form
    • Http
      • Client
        • Adapter
        • Auth
      • Cookie
      • Exception
      • Middleware
      • Session
    • I18n
      • Formatter
      • Middleware
      • Parser
    • Log
      • Engine
    • Mailer
      • Exception
      • Transport
    • Network
      • Exception
    • ORM
      • Association
      • Behavior
        • Translate
      • Exception
      • Locator
      • Rule
    • Routing
      • Exception
      • Filter
      • Middleware
      • Route
    • Shell
      • Helper
      • Task
    • TestSuite
      • Fixture
      • Stub
    • Utility
      • Exception
    • Validation
    • View
      • Exception
      • Form
      • Helper
      • Widget
  • None

Classes

  • Event
  • EventList
  • EventManager

Interfaces

  • EventDispatcherInterface
  • EventInterface
  • EventListenerInterface
  • EventManagerInterface

Traits

  • EventDispatcherTrait
  • EventManagerTrait

Class EventManager

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\EventManager implements Cake\Event\EventManagerInterface
Namespace: Cake\Event
Location: Event/EventManager.php

Properties summary

  • $_eventList protected
    Cake\Event\EventList|null
    The event list object.
  • $_generalManager protected static
    Cake\Event\EventManager
    The globally available instance, used for dispatching events attached from any scope
  • $_isGlobal protected
    boolean
    Internal flag to distinguish a common manager from the singleton
  • $_listeners protected
    array
    List of listener callbacks associated to
  • $_trackEvents protected
    boolean
    Enables automatic adding of events to the event list object if it is present.
  • $defaultPriority public static
    integer
    The default priority queue value for new, attached listeners

Method Summary

  • __debugInfo() public
    Debug friendly object properties.
  • _attachSubscriber() protected

    Auxiliary function to attach all implemented callbacks of a Cake\Event\EventListenerInterface class instance as individual methods on this manager

  • _callListener() protected
    Calls a listener.
  • _detachSubscriber() protected
    Auxiliary function to help detach all listeners provided by an object implementing EventListenerInterface
  • _extractCallable() protected

    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

  • addEventToList() public
    Adds an event to the list if the event list object is present.
  • attach() public deprecated
    Adds a new listener to an event.
  • detach() public deprecated
    Removes a listener from the active listeners.
  • dispatch() public
    Dispatches a new event to all configured listeners
  • getEventList() public
    Returns the event list.
  • instance() public 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

  • isTrackingEvents() public
    Returns whether this manager is set up to track events
  • listeners() public
    Returns a list of all listeners for an eventKey in the order they should be called
  • matchingListeners() public
    Returns the listeners matching a specified pattern
  • off() public
    Remove a listener from the active listeners.
  • on() public
    Adds a new listener to an event.
  • prioritisedListeners() public
    Returns the listeners for the specified event key indexed by priority
  • setEventList() public
    Enables the listing of dispatched events.
  • trackEvents() public
    Enables / disables event tracking at runtime.
  • unsetEventList() public
    Disables the listing of dispatched events.

Method Detail

__debugInfo() public ¶

__debugInfo( )

Debug friendly object properties.

Returns
array

_attachSubscriber() protected ¶

_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

Parameters
Cake\Event\EventListenerInterface $subscriber
Event listener.

_callListener() protected ¶

_callListener( callable $listener , Cake\Event\Event $event )

Calls a listener.

Parameters
callable $listener
The listener to trigger.
Cake\Event\Event $event
Event instance.
Returns
mixed
The result of the $listener function.

_detachSubscriber() protected ¶

_detachSubscriber( Cake\Event\EventListenerInterface $subscriber , string|null $eventKey = null )

Auxiliary function to help detach all listeners provided by an object implementing EventListenerInterface

Parameters
Cake\Event\EventListenerInterface $subscriber
the subscriber to be detached
string|null $eventKey optional null
optional event key name to unsubscribe the listener from

_extractCallable() protected ¶

_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

Parameters
array $function
the array taken from a handler definition for an event
Cake\Event\EventListenerInterface $object
The handler object
Returns
callable

addEventToList() public ¶

addEventToList( Cake\Event\Event $event )

Adds an event to the list if the event list object is present.

Parameters
Cake\Event\Event $event
An event to add to the list.
Returns

$this

attach() public deprecated ¶

attach( callable|Cake\Event\EventListenerInterface $callable , string|null $eventKey = null , array $options = [] )

Adds a new listener to an event.

Deprecated
3.0.0 Use on() instead.
Parameters
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 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.

string|null $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

array $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.

Throws
InvalidArgumentException

When event key is missing or callable is not an instance of Cake\Event\EventListenerInterface.


detach() public deprecated ¶

detach( callable|Cake\Event\EventListenerInterface $callable , string|null $eventKey = null )

Removes a listener from the active listeners.

Deprecated
3.0.0 Use off() instead.
Parameters
callable|Cake\Event\EventListenerInterface $callable
any valid PHP callback type or an instance of EventListenerInterface
string|null $eventKey optional null
The event unique identifier name with which the callback has been associated

dispatch() 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
Implementation of
Cake\Event\EventManagerInterface::dispatch()

getEventList() public ¶

getEventList( )

Returns the event list.

Returns
Cake\Event\EventList

instance() public static ¶

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

Parameters
Cake\Event\EventManager|null $manager optional null
Event manager instance.
Returns
Cake\Event\EventManager
The global event manager

isTrackingEvents() public ¶

isTrackingEvents( )

Returns whether this manager is set up to track events

Returns
boolean

listeners() 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
array
Implementation of
Cake\Event\EventManagerInterface::listeners()

matchingListeners() public ¶

matchingListeners( string $eventKeyPattern )

Returns the listeners matching a specified pattern

Parameters
string $eventKeyPattern
Pattern to match.
Returns
array

off() public ¶

off( string|Cake\Event\EventListenerInterface $eventKey , callable|null $callable = null )

Remove a listener from the active listeners.

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
Implementation of
Cake\Event\EventManagerInterface::off()

on() public ¶

on( string|Cake\Event\EventListenerInterface|null $eventKey = null , array|callable $options = [] , callable|null $callable = null )

Adds a new listener to an event.

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
InvalidArgumentException

When event key is missing or callable is not an instance of Cake\Event\EventListenerInterface.


Implementation of
Cake\Event\EventManagerInterface::on()

prioritisedListeners() public ¶

prioritisedListeners( string $eventKey )

Returns the listeners for the specified event key indexed by priority

Parameters
string $eventKey
Event key.
Returns
array

setEventList() public ¶

setEventList( Cake\Event\EventList $eventList )

Enables the listing of dispatched events.

Parameters
Cake\Event\EventList $eventList
The event list object to use.
Returns

$this

trackEvents() public ¶

trackEvents( boolean $enabled )

Enables / disables event tracking at runtime.

Parameters
boolean $enabled
True or false to enable / disable it.
Returns

$this

unsetEventList() public ¶

unsetEventList( )

Disables the listing of dispatched events.

Returns

$this

Properties detail

$_eventList ¶

protected Cake\Event\EventList|null

The event list object.

$_generalManager ¶

protected static Cake\Event\EventManager

The globally available instance, used for dispatching events attached from any scope

$_isGlobal ¶

protected boolean

Internal flag to distinguish a common manager from the singleton

false

$_listeners ¶

protected array

List of listener callbacks associated to

[]

$_trackEvents ¶

protected boolean

Enables automatic adding of events to the event list object if it is present.

false

$defaultPriority ¶

public static integer

The default priority queue value for new, attached listeners

10
Follow @CakePHP
#IRC
OpenHub
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Logos & Trademarks
  • Community
  • Team
  • Issues (Github)
  • YouTube Channel
  • Get Involved
  • Bakery
  • Featured Resources
  • Newsletter
  • Certification
  • My CakePHP
  • CakeFest
  • Facebook
  • Twitter
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs