Repository navigation
Internals Event EventDispatcher
Framework Internals · Subsystem overview · Developer guide
Source: awt_src/classes/event/EventDispatcher.php · Snapshot 8411f4287706.
The request-wide event dispatcher calls listeners synchronously in registration order and collects their arrays. Listener exceptions propagate.
use event\interfaces\IEvent;
use event\interfaces\IEventListener;class EventDispatcherSource description (behavioral corrections are recorded in Known discrepancies):
Class EventDispatcher
The EventDispatcher class manages the registration and dispatching of events within the application. It allows event listeners to be added for specific events and triggers those listeners when the associated event is dispatched.
Declarations below preserve visibility, type, default and modifiers exactly. A typed property without an initializer remains uninitialized until its constructor or another method assigns it. Mutable fields belong to this instance unless marked static; readonly fields can be initialized once. Constructor-promoted properties are also listed below.
| Member | Declaration | Purpose or source contract |
|---|---|---|
| $listeners | public array $listeners = []; |
@var array $listeners An associative array where keys are event names and values are arrays of registered event listeners for those events. |
| Method | Signature |
|---|---|
| addListener | public function addListener(string $eventName, IEventListener $listener): void |
| dispatch | public function dispatch(IEvent $event): array |
| removeListeners | public function removeListeners(string $eventName): void |
public function addListener(string $eventName, IEventListener $listener): void| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$eventName |
string $eventName |
The name of the event to listen for. |
$listener |
IEventListener $listener |
An instance of a class that implements |
Adds an event listener for a specified event name.
This method allows a listener to be registered for a specific event, enabling the listener to respond when that event is dispatched.
@param string $eventName The name of the event to listen for. @param IEventListener $listener An instance of a class that implements IEventListener to handle the event. @return void
State writes: $this->listeners[$eventName][].
Implementation, validation guards and interaction order
/**
* Adds an event listener for a specified event name.
*
* This method allows a listener to be registered for a specific
* event, enabling the listener to respond when that event is
* dispatched.
*
* @param string $eventName The name of the event to listen for.
* @param IEventListener $listener An instance of a class that implements
* IEventListener to handle the event.
* @return void
*/
public function addListener(string $eventName, IEventListener $listener): void
{
$this->listeners[$eventName][] = $listener;
}public function dispatch(IEvent $event): array| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$event |
IEvent $event |
An instance of a class that implements |
Dispatches an event to its registered listeners.
This method triggers the handling of an event by invoking all listeners registered for that event name. The results of each listener's handling are collected and returned.
@param IEvent $event An instance of a class that implements IEvent, representing the event to be dispatched. @return array An array of results returned by each listener that handled the event.
Return expressions (including local callbacks): $result.
Implementation, validation guards and interaction order
/**
* Dispatches an event to its registered listeners.
*
* This method triggers the handling of an event by invoking all
* listeners registered for that event name. The results of each
* listener's handling are collected and returned.
*
* @param IEvent $event An instance of a class that implements
* IEvent, representing the event to be dispatched.
* @return array An array of results returned by each listener that
* handled the event.
*/
public function dispatch(IEvent $event): array
{
$eventName = $event->getName();
$result = [];
if (!empty($this->listeners[$eventName])) {
foreach ($this->listeners[$eventName] as $listener) {
$result[] = $listener->handle($event);
}
}
return $result;
}public function removeListeners(string $eventName): void| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$eventName |
string $eventName |
* @return void |
Removes all listeners for a specific event. @param string $eventName @return void
Computes or delegates the operation shown below; no explicit receiver property assignment or throw occurs in this method.
Implementation, validation guards and interaction order
/**
* Removes all listeners for a specific event.
* @param string $eventName
* @return void
*/
public function removeListeners(string $eventName): void
{
if(isset($this->listeners[$eventName]))
unset(
$this->listeners[$eventName]
);
}AWT Framework Wiki · Home · Installation Guide · Developer Guide · Framework Internals
Philosophy · Architecture · Known discrepancies · Verification
Installation Guide
Developer Guide
- Learning sequence
- First package
- Package structure
- Lifecycle
- Runtimes
- Events and objects
- Routing and controllers
- Views and resources
- Database and models
- Storage and caching
- Configuration and CLI
- Responses and errors
- Extension points
Framework Internals
- Architecture
- Bootstrap
- Packages
- Runtime
- Events and context
- Objects
- HTTP routing and controllers
- Rendering
- Blade integration
- Database
- Models
- Storage and caching
- Settings
- CLI
- Identity and sessions
- Responses
- Errors
- Complete source inventory
Documentation notes