Documentation

Manager extends AbstractManager
in package
implements EventDispatcherInterface, ListenerProviderInterface

Event manager class

Tags
category

Pop

author

Nick Sagona, III nick@popphp.org

copyright

Copyright (c) 2009-2026 Nick Sagona, III

license

https://www.popphp.org/license New BSD License

version
5.0.0

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 = []

$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
static

addItems()

Add items

public addItems(array<string|int, mixed> $items) : static
Parameters
$items : array<string|int, mixed>
Return values
static

dispatch()

Dispatch an event to its class-indexed listeners

public dispatch(object $event) : object
Parameters
$event : object
Return values
object

get()

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
ArrayIterator

getListenersForEvent()

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
bool

hasItem()

Determine whether the manager has an item

public hasItem(string $name) : bool
Parameters
$name : string
Return values
bool

hasItems()

Determine whether the manager has items

public hasItems() : bool
Return values
bool

listen()

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
static

off()

Detach an event listener

public off(string $name, mixed $action) : static
Parameters
$name : string
$action : mixed
Return values
static

offsetExists()

Determine if an item exists

public offsetExists(string $offset) : bool
Parameters
$offset : string
Return values
bool

offsetGet()

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
static

removeItem()

Remove an item

public removeItem(mixed $name) : static
Parameters
$name : mixed
Return values
static

setItems()

Set items

public setItems(array<string|int, mixed> $items) : static
Parameters
$items : array<string|int, mixed>
Return values
static

trigger()

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

        
On this page

Search results