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
$eventPrototype
protected
EventInterface
$eventPrototype
Prototype to use when creating an event at trigger().
$events
Subscribed events and their listeners
protected
array<string|int, array<string|int, mixed>>
$events
= []
STRUCTURE:
[
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
= []
$sharedManager
Shared event manager
protected
null|SharedEventManagerInterface
$sharedManager
= null
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
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
Return values
callable —clearListeners()
Clear all listeners for a given event
public
clearListeners(mixed $eventName) : void
Parameters
- $eventName : mixed
Tags
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
Return values
void —getIdentifiers()
Get the identifier(s) for this EventManager
public
getIdentifiers() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —getSharedManager()
Retrieve the shared event manager, if composed.
public
getSharedManager() : null|SharedEventManagerInterface
Return values
null|SharedEventManagerInterface —$sharedEventManager
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
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
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
Return values
ResponseCollection —triggerEvent()
Trigger an event
public
triggerEvent(EventInterface $event) : ResponseCollection
Parameters
- $event : EventInterface
Tags
Return values
ResponseCollection —triggerEventUntil()
Trigger an event, applying a callback to each listener result.
public
triggerEventUntil(callable $callback, EventInterface $event) : ResponseCollection
Parameters
- $callback : callable
- $event : EventInterface
Tags
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
Return values
ResponseCollection —triggerListeners()
Trigger listeners
protected
triggerListeners(EventInterface $event[, null|callable $callback = null ]) : ResponseCollection
Actual functionality for triggering listeners, to which trigger() delegate.
Parameters
- $event : EventInterface
- $callback : null|callable = null