Emitter
in package
implements
EmitterInterface
Table of Contents
Interfaces
Properties
- $listeners : array<string|int, mixed>
- The registered listeners.
- $sortedListeners : array<string|int, ListenerInterface>
- The sorted listeners
Methods
- 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.
- removeAllListeners() : $this
- Remove all listeners for an event.
- removeListener() : $this
- Remove a specific listener for an event.
- 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.
Properties
$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
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
boolremoveAllListeners()
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
$thisuseListenerProvider()
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