Fr3nch13/CakePHP Utilities

EventManagerInterface

Interface EventManagerInterface

Table of Contents

Methods

dispatch()  : EventInterface
Dispatches a new event to all configured listeners
listeners()  : array<string|int, mixed>
Returns a list of all listeners for an eventKey in the order they should be called
off()  : $this
Remove a listener from the active listeners.
on()  : $this
Adds a new listener to an event.

Methods

listeners()

Returns a list of all listeners for an eventKey in the order they should be called

public listeners(string $eventKey) : array<string|int, mixed>
Parameters
$eventKey : string

Event key.

Return values
array<string|int, mixed>

off()

Remove a listener from the active listeners.

public off(EventListenerInterface|callable|string $eventKey[, EventListenerInterface|callable|null $callable = null ]) : $this

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
$eventKey : EventListenerInterface|callable|string

The event unique identifier name with which the callback has been associated, or the $listener you want to remove.

$callable : EventListenerInterface|callable|null = null

The callback you want to detach.

Return values
$this

on()

Adds a new listener to an event.

public on(EventListenerInterface|string $eventKey[, callable|array<string|int, mixed> $options = [] ][, callable|null $callable = null ]) : $this

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);
Parameters
$eventKey : EventListenerInterface|string

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 : callable|array<string|int, mixed> = []

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 : callable|null = null

The callable function you want invoked.

Tags
throws
InvalidArgumentException

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

Return values
$this

        
On this page

Search results