Basic Usage
The Emitter
class is the main point of interest in the Event package. This is where you
register listeners and trigger events.
Creating the Emitter
use League\Event\Emitter;
$emitter = new Emitter;
Registering Listeners
Listeners are registered through the addListener
method.
$emitter->addListener('event.name', $listener);
The listener can be of two types:
Listener Priority
Optionally event flow can be influenced by setting a priority. Priorities are represented as integers.
$emitter->addListener('event.name', $listener, 100);
The League\Event\EmitterInterface
has 3 predefined priorities:
EmitterInterface::P_HIGH
: 100EmitterInterface::P_NORMAL
: 0EmitterInterface::P_LOW
: -100
Emitting events
Events are emitted using the emit
function.
$event = $emitter->emit($event);
The event can be of two types:
Emitting events in batches
$events = $emitter->emitBatch([$event, $event, $event]);
Emit Return Values
Events emitted are returned as the result. When emitting events in batches an array of events is returned.