EventManager
extends Emitter
in package
Class EventManager.
Register handler, send event.
Tags
Table of Contents
Constants
- SIGNAL_COMP_COMPILATION = 'compilation'
- Indicate that the Unix Signal is not supported because PHP has not been compiled with signal support
- SIGNAL_COMP_OK = 'ok'
- Indicate that the Unix Signal is supported by the system and PHP
- SIGNAL_COMP_WINDOWS = 'windows'
- Indicate that the Unix Signal is not supported because we are on a Windows System
Properties
- $application : Application
- The current Phar-Builder application
- $listeners : array<string|int, mixed>
- The registered listeners.
- $sortedListeners : array<string|int, ListenerInterface>
- The sorted listeners
Methods
- __construct() : mixed
- EventManager constructor.
- addListener() : $this
- Add a listener for an event.
- addOneTimeListener() : $this
- Add a one time listener for an event.
- emit() : EventInterface
- Emit an event.
- emitBatch() : array<string|int, mixed>
- Emit a batch of events.
- emitGeneratedEvents() : array<string|int, EventInterface>
- Release all events stored in a generator
- getListeners() : array<string|int, mixed>
- Get all the listeners for an event.
- hasListeners() : bool
- Check whether an event has listeners.
- isSignalCompatible() : string
- Check is the current system and PHP support UNIX signal
- registerApplication() : void
- Register the application event handler and the Unix signal handler
- removeAllListeners() : $this
- Remove all listeners for an event.
- removeListener() : $this
- Remove a specific listener for an event.
- unixSignalHandler() : void
- The Unix signal handler. (Re-send to the application event handler)
- useListenerProvider() : $this
- Use a provider to add listeners.
- clearSortedListeners() : mixed
- Clear the sorted listeners for an event
- ensureEvent() : EventInterface
- Ensure event input is of type EventInterface or convert it.
- ensureListener() : ListenerInterface
- Ensure the input is a listener.
- getSortedListeners() : array<string|int, ListenerInterface>
- Get the listeners sorted by priority for a given event.
- invokeListeners() : void
- Invoke the listeners for an event.
- prepareEvent() : array<string|int, mixed>
- Prepare an event for emitting.
Constants
SIGNAL_COMP_COMPILATION
Indicate that the Unix Signal is not supported because PHP has not been compiled with signal support
public
mixed
SIGNAL_COMP_COMPILATION
= 'compilation'
SIGNAL_COMP_OK
Indicate that the Unix Signal is supported by the system and PHP
public
mixed
SIGNAL_COMP_OK
= 'ok'
SIGNAL_COMP_WINDOWS
Indicate that the Unix Signal is not supported because we are on a Windows System
public
mixed
SIGNAL_COMP_WINDOWS
= 'windows'
Properties
$application
The current Phar-Builder application
protected
Application
$application
$listeners
The registered listeners.
protected
array<string|int, mixed>
$listeners
= []
$sortedListeners
The sorted listeners
protected
array<string|int, ListenerInterface>
$sortedListeners
= []
Listeners will get sorted and stored for re-use.
Methods
__construct()
EventManager constructor.
public
__construct(Application $application) : mixed
Parameters
- $application : Application
-
The Phar-Builder application
addListener()
Add a listener for an event.
public
addListener(mixed $event, mixed $listener[, mixed $priority = self::P_NORMAL ]) : $this
Parameters
- $event : mixed
- $listener : mixed
- $priority : mixed = self::P_NORMAL
Tags
Return values
$thisaddOneTimeListener()
Add a one time listener for an event.
public
addOneTimeListener(mixed $event, mixed $listener[, mixed $priority = self::P_NORMAL ]) : $this
Parameters
- $event : mixed
- $listener : mixed
- $priority : mixed = self::P_NORMAL
Tags
Return values
$thisemit()
Emit an event.
public
emit(mixed $event) : EventInterface
Parameters
- $event : mixed
Tags
Return values
EventInterfaceemitBatch()
Emit a batch of events.
public
emitBatch(array<string|int, mixed> $events) : array<string|int, mixed>
Parameters
- $events : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>emitGeneratedEvents()
Release all events stored in a generator
public
emitGeneratedEvents(GeneratorInterface $generator) : array<string|int, EventInterface>
Parameters
- $generator : GeneratorInterface
Tags
Return values
array<string|int, EventInterface>getListeners()
Get all the listeners for an event.
public
getListeners(mixed $event) : array<string|int, mixed>
Parameters
- $event : mixed
Tags
Return values
array<string|int, mixed>hasListeners()
Check whether an event has listeners.
public
hasListeners(mixed $event) : bool
Parameters
- $event : mixed
Tags
Return values
boolisSignalCompatible()
Check is the current system and PHP support UNIX signal
public
isSignalCompatible() : string
Return values
stringregisterApplication()
Register the application event handler and the Unix signal handler
public
registerApplication() : void
removeAllListeners()
Remove all listeners for an event.
public
removeAllListeners(mixed $event) : $this
Parameters
- $event : mixed
Tags
Return values
$thisremoveListener()
Remove a specific listener for an event.
public
removeListener(mixed $event, mixed $listener) : $this
Parameters
- $event : mixed
- $listener : mixed
Tags
Return values
$thisunixSignalHandler()
The Unix signal handler. (Re-send to the application event handler)
public
unixSignalHandler(int $signal) : void
Parameters
- $signal : int
-
The Unix signal code
Tags
useListenerProvider()
Use a provider to add listeners.
public
useListenerProvider(ListenerProviderInterface $provider) : $this
Parameters
- $provider : ListenerProviderInterface
Tags
Return values
$thisclearSortedListeners()
Clear the sorted listeners for an event
protected
clearSortedListeners(mixed $event) : mixed
Parameters
- $event : mixed
ensureEvent()
Ensure event input is of type EventInterface or convert it.
protected
ensureEvent(string|EventInterface $event) : EventInterface
Parameters
- $event : string|EventInterface
Tags
Return values
EventInterfaceensureListener()
Ensure the input is a listener.
protected
ensureListener(ListenerInterface|callable $listener) : ListenerInterface
Parameters
- $listener : ListenerInterface|callable
Tags
Return values
ListenerInterfacegetSortedListeners()
Get the listeners sorted by priority for a given event.
protected
getSortedListeners(string $event) : array<string|int, ListenerInterface>
Parameters
- $event : string
Return values
array<string|int, ListenerInterface>invokeListeners()
Invoke the listeners for an event.
protected
invokeListeners(string $name, EventInterface $event, array<string|int, mixed> $arguments) : void
Parameters
- $name : string
- $event : EventInterface
- $arguments : array<string|int, mixed>
prepareEvent()
Prepare an event for emitting.
protected
prepareEvent(string|EventInterface $event) : array<string|int, mixed>
Parameters
- $event : string|EventInterface