Manager
extends AbstractManager
in package
implements
EventDispatcherInterface, ListenerProviderInterface
Event manager class
Tags
Table of Contents
Interfaces
- EventDispatcherInterface
- ListenerProviderInterface
Properties
- $classListeners : array<string, SplPriorityQueue>
- Class-indexed listeners, keyed by exact event class name
- $items : array<string|int, mixed>
- Manager items
- $results : array<string|int, mixed>
- Event results
Methods
- __construct() : mixed
- Constructor
- __get() : mixed
- Get an item
- __isset() : bool
- Determine if an item exists
- __set() : void
- Set an event
- __unset() : void
- Unset an item
- addItem() : static
- Add an item
- addItems() : static
- Add items
- count() : int
- Return count
- dispatch() : object
- Dispatch an event to its class-indexed listeners
- get() : mixed
- Return an event
- getItem() : mixed
- Get an item
- getItems() : array<string|int, mixed>
- Get items
- getIterator() : ArrayIterator
- Get iterator
- getListenersForEvent() : iterable<string|int, mixed>
- Get the class-indexed listeners for an event, matched by exact event class only
- getResults() : mixed
- Return the event results
- has() : bool
- Determine whether the event manager has an event registered with it
- hasItem() : bool
- Determine whether the manager has an item
- hasItems() : bool
- Determine whether the manager has items
- listen() : static
- Register a listener for an event class - called with the raw event object as its sole argument
- off() : static
- Detach an event listener
- offsetExists() : bool
- Determine if an item exists
- offsetGet() : mixed
- Get an item
- offsetSet() : void
- Set an event
- offsetUnset() : void
- Unset an item
- on() : static
- Attach an event listener
- removeItem() : static
- Remove an item
- setItems() : static
- Set items
- trigger() : void
- Trigger an event listener
- dispatchNamed() : void
- Dispatch a name-indexed event's listeners - always called positionally, sourced from $event->toParams() plus an appended 'result' (previous listener's return value, same chaining as before this event object existed) and 'event' (the event object itself, appended last so it never shifts the positional index of a key an existing listener already reads - a listener that wants stopPropagation() declares one extra trailing parameter to receive it, everyone else is unaffected).
Properties
$classListeners
Class-indexed listeners, keyed by exact event class name
protected
array<string, SplPriorityQueue>
$classListeners
= []
$items
Manager items
protected
array<string|int, mixed>
$items
= []
$results
Event results
protected
array<string|int, mixed>
$results
= []
Methods
__construct()
Constructor
public
__construct([string|null $name = null ][, mixed $action = null ][, int $priority = 0 ]) : mixed
Instantiate the event manager object.
Parameters
- $name : string|null = null
- $action : mixed = null
- $priority : int = 0
__get()
Get an item
public
__get(string $name) : mixed
Parameters
- $name : string
__isset()
Determine if an item exists
public
__isset(string $name) : bool
Parameters
- $name : string
Return values
bool__set()
Set an event
public
__set(string $name, mixed $value) : void
Parameters
- $name : string
- $value : mixed
__unset()
Unset an item
public
__unset(string $name) : void
Parameters
- $name : string
addItem()
Add an item
public
addItem(mixed $item[, mixed $name = null ]) : static
Parameters
- $item : mixed
- $name : mixed = null
Return values
staticaddItems()
Add items
public
addItems(array<string|int, mixed> $items) : static
Parameters
- $items : array<string|int, mixed>
Return values
staticcount()
Return count
public
count() : int
Return values
intdispatch()
Dispatch an event to its class-indexed listeners
public
dispatch(object $event) : object
Parameters
- $event : object
Return values
objectget()
Return an event
public
get(string $name) : mixed
Parameters
- $name : string
getItem()
Get an item
public
getItem(mixed $name) : mixed
Parameters
- $name : mixed
getItems()
Get items
public
getItems() : array<string|int, mixed>
Return values
array<string|int, mixed>getIterator()
Get iterator
public
getIterator() : ArrayIterator
Return values
ArrayIteratorgetListenersForEvent()
Get the class-indexed listeners for an event, matched by exact event class only
public
getListenersForEvent(object $event) : iterable<string|int, mixed>
Parameters
- $event : object
Return values
iterable<string|int, mixed>getResults()
Return the event results
public
getResults(string $name) : mixed
Parameters
- $name : string
has()
Determine whether the event manager has an event registered with it
public
has(string $name) : bool
Parameters
- $name : string
Return values
boolhasItem()
Determine whether the manager has an item
public
hasItem(string $name) : bool
Parameters
- $name : string
Return values
boolhasItems()
Determine whether the manager has items
public
hasItems() : bool
Return values
boollisten()
Register a listener for an event class - called with the raw event object as its sole argument
public
listen(string $eventClass, callable $listener[, int $priority = 0 ]) : static
Parameters
- $eventClass : string
- $listener : callable
- $priority : int = 0
Return values
staticoff()
Detach an event listener
public
off(string $name, mixed $action) : static
Parameters
- $name : string
- $action : mixed
Return values
staticoffsetExists()
Determine if an item exists
public
offsetExists(string $offset) : bool
Parameters
- $offset : string
Return values
booloffsetGet()
Get an item
public
offsetGet(mixed $offset) : mixed
Parameters
- $offset : mixed
offsetSet()
Set an event
public
offsetSet(mixed $offset, mixed $value) : void
Parameters
- $offset : mixed
- $value : mixed
offsetUnset()
Unset an item
public
offsetUnset(mixed $offset) : void
Parameters
- $offset : mixed
on()
Attach an event listener
public
on(string $name, mixed $action[, int $priority = 0 ]) : static
$event->on('event.name', 'someFunction'); $event->on('event.name', function() { ... }); $event->on('event.name', new SomeClass()); $event->on('event.name', [new SomeClass, 'foo']); $event->on('event.name', 'SomeClass'); $event->on('event.name', 'SomeClass->foo'); $event->on('event.name', 'SomeClass::bar');
Parameters
- $name : string
- $action : mixed
- $priority : int = 0
Return values
staticremoveItem()
Remove an item
public
removeItem(mixed $name) : static
Parameters
- $name : mixed
Return values
staticsetItems()
Set items
public
setItems(array<string|int, mixed> $items) : static
Parameters
- $items : array<string|int, mixed>
Return values
statictrigger()
Trigger an event listener
public
trigger(string $name[, array<string|int, mixed> $params = [] ]) : void
Parameters
- $name : string
- $params : array<string|int, mixed> = []
dispatchNamed()
Dispatch a name-indexed event's listeners - always called positionally, sourced from $event->toParams() plus an appended 'result' (previous listener's return value, same chaining as before this event object existed) and 'event' (the event object itself, appended last so it never shifts the positional index of a key an existing listener already reads - a listener that wants stopPropagation() declares one extra trailing parameter to receive it, everyone else is unaffected).
protected
dispatchNamed(string $name, AbstractEvent $event) : void
Parameters
- $name : string
- $event : AbstractEvent