FileAccess Orion

EventManager
in package
implements EventManagerInterface

Event manager: notification system

Use the EventManager when you want to create a per-instance notification system for your objects.

Interfaces, Classes, Traits and Enums

EventManagerInterface
Interface for messengers

Table of Contents

$eventPrototype  : EventInterface
$events  : array<string|int, array<string|int, mixed>>
Subscribed events and their listeners
$identifiers  : array<string|int, mixed>
Identifiers, used to pull shared signals from SharedEventManagerInterface instance
$sharedManager  : null|SharedEventManagerInterface
Shared event manager
__construct()  : mixed
Constructor
addIdentifiers()  : void
Add identifier(s) (appends to any currently set identifiers)
attach()  : callable
Attach a listener to an event
clearListeners()  : void
Clear all listeners for a given event
detach()  : void
Detach a listener.
getIdentifiers()  : array<string|int, mixed>
Get the identifier(s) for this EventManager
getSharedManager()  : null|SharedEventManagerInterface
Retrieve the shared event manager, if composed.
prepareArgs()  : ArrayObject
Prepare arguments
setEventPrototype()  : void
Provide an event prototype to use with trigger().
setIdentifiers()  : void
Set the identifiers (overrides any currently set identifiers)
trigger()  : ResponseCollection
Create and trigger an event.
triggerEvent()  : ResponseCollection
Trigger an event
triggerEventUntil()  : ResponseCollection
Trigger an event, applying a callback to each listener result.
triggerUntil()  : ResponseCollection
Create and trigger an event, applying a callback to each listener result.
triggerListeners()  : ResponseCollection
Trigger listeners

Properties

$events

Subscribed events and their listeners

protected array<string|int, array<string|int, mixed>> $events = []

STRUCTURE: [ => [ => [ 0 => [, ...] ], ... ], ... ]

NOTE: This structure helps us to reuse the list of listeners instead of first iterating over it and generating a new one -> In result it improves performance by up to 25% even if it looks a bit strange

$identifiers

Identifiers, used to pull shared signals from SharedEventManagerInterface instance

protected array<string|int, mixed> $identifiers = []

Methods

__construct()

Constructor

public __construct([SharedEventManagerInterface $sharedEventManager = null ][, array<string|int, mixed> $identifiers = [] ]) : mixed

Allows optionally specifying identifier(s) to use to pull signals from a SharedEventManagerInterface.

Parameters
$sharedEventManager : SharedEventManagerInterface = null
$identifiers : array<string|int, mixed> = []
Return values
mixed

addIdentifiers()

Add identifier(s) (appends to any currently set identifiers)

public addIdentifiers(array<string|int, mixed> $identifiers) : void
Parameters
$identifiers : array<string|int, mixed>
Tags
inheritDoc
Return values
void

attach()

Attach a listener to an event

public attach(mixed $eventName, callable $listener[, mixed $priority = 1 ]) : callable
Parameters
$eventName : mixed

Event to which to listen.

$listener : callable
$priority : mixed = 1

Priority at which to register listener.

Tags
inheritDoc
Return values
callable

clearListeners()

Clear all listeners for a given event

public clearListeners(mixed $eventName) : void
Parameters
$eventName : mixed
Tags
inheritDoc
Return values
void

detach()

Detach a listener.

public detach(callable $listener[, mixed $eventName = null ][, mixed $force = false ]) : void
Parameters
$listener : callable
$eventName : mixed = null

Event from which to detach; null and '*' indicate all events.

$force : mixed = false
Tags
inheritDoc
throws
InvalidArgumentException

for invalid event types.

Return values
void

getIdentifiers()

Get the identifier(s) for this EventManager

public getIdentifiers() : array<string|int, mixed>
Tags
inheritDoc
Return values
array<string|int, mixed>

prepareArgs()

Prepare arguments

public prepareArgs(array<string|int, mixed> $args) : ArrayObject

Use this method if you want to be able to modify arguments from within a listener. It returns an ArrayObject of the arguments, which may then be passed to trigger().

Parameters
$args : array<string|int, mixed>
Return values
ArrayObject

setEventPrototype()

Provide an event prototype to use with trigger().

public setEventPrototype(EventInterface $prototype) : void
Parameters
$prototype : EventInterface
Tags
inheritDoc
Return values
void

setIdentifiers()

Set the identifiers (overrides any currently set identifiers)

public setIdentifiers(array<string|int, mixed> $identifiers) : void
Parameters
$identifiers : array<string|int, mixed>
Tags
inheritDoc
Return values
void

trigger()

Create and trigger an event.

public trigger(mixed $eventName[, mixed $target = null ][, mixed $argv = [] ]) : ResponseCollection
Parameters
$eventName : mixed
$target : mixed = null
$argv : mixed = []
Tags
inheritDoc
Return values
ResponseCollection

triggerUntil()

Create and trigger an event, applying a callback to each listener result.

public triggerUntil(callable $callback, mixed $eventName[, mixed $target = null ][, mixed $argv = [] ]) : ResponseCollection
Parameters
$callback : callable
$eventName : mixed
$target : mixed = null
$argv : mixed = []
Tags
inheritDoc
Return values
ResponseCollection

Search results