Emitter
in package
Central event emitter that manages event broadcasting across multiple channels.
The Emitter class serves as the core component of the Neuron event system, coordinating event distribution across registered broadcasters. It provides a unified interface for event emission while supporting multiple broadcasting strategies through the IBroadcaster interface.
Key responsibilities:
- Register and manage multiple event broadcasters
- Emit events to all registered broadcasters simultaneously
- Register listeners across all broadcasters for consistent event handling
- Prevent duplicate broadcaster registrations
- Provide centralized event coordination for the entire application
The emitter follows a publish-subscribe pattern where events are published to all registered broadcasters, which then distribute them to their respective listeners based on event names and filtering criteria.
Tags
Table of Contents
Properties
- $broadcasters : array<string|int, mixed>
Methods
- addListener() : bool
- Registers an event with all broadcasters.
- emit() : void
- Emits an event across all registered broadcasters.
- getBroadcasters() : array<string|int, mixed>
- Returns a list of all registered broadcasters.
- registerBroadcaster() : bool
- Registers a broadcaster to emit events to.
Properties
$broadcasters
private
array<string|int, mixed>
$broadcasters
= []
Methods
addListener()
Registers an event with all broadcasters.
public
addListener(string $eventName, IListener $listener) : bool
Parameters
- $eventName : string
- $listener : IListener
Return values
boolemit()
Emits an event across all registered broadcasters.
public
emit(mixed $event) : void
Parameters
- $event : mixed
getBroadcasters()
Returns a list of all registered broadcasters.
public
getBroadcasters() : array<string|int, mixed>
Return values
array<string|int, mixed> —Array of broadcasters.
registerBroadcaster()
Registers a broadcaster to emit events to.
public
registerBroadcaster(IBroadcaster $newBroadcaster) : bool
Parameters
- $newBroadcaster : IBroadcaster