EventDispatcher
in package
Dispatches events and queues them for the rest of the request, so listeners registered later still receive them.
Late binding matters for Nette AJAX and components created lazily (e.g. in a Multiplier).
Table of Contents
Properties
- $debugMode : bool
- $eventQueue : array<string, array<int, mixed>>
- $fallbacks : array<int, callable>
- $listeners : array<string, array<int, callable>>
Methods
- __construct() : mixed
- addFallback() : void
- addListener() : void
- Registers a listener and immediately replays the already queued payloads of that event to it.
- clear() : void
- dispatch() : void
- Dispatches an event to the current listeners and fallbacks and keeps it queued.
- logError() : void
Properties
$debugMode
private
bool
$debugMode
= false
$eventQueue
private
array<string, array<int, mixed>>
$eventQueue
= []
payloads dispatched during this request, by event name
$fallbacks
private
array<int, callable>
$fallbacks
= []
fallbacks called for every dispatched event
$listeners
private
array<string, array<int, callable>>
$listeners
= []
registered listeners by event name
Methods
__construct()
public
__construct([bool $debugMode = false ]) : mixed
Parameters
- $debugMode : bool = false
addFallback()
public
addFallback(callable $fallback) : void
Parameters
- $fallback : callable
addListener()
Registers a listener and immediately replays the already queued payloads of that event to it.
public
addListener(string $eventName, callable $listener) : void
Without the replay, a component created after the dispatch (typical for AJAX) would miss the event.
Parameters
- $eventName : string
- $listener : callable
clear()
public
clear() : void
dispatch()
Dispatches an event to the current listeners and fallbacks and keeps it queued.
public
dispatch(string $eventName[, mixed $data = [] ]) : void
The queue lets components that Nette creates later in the request (e.g. in a template) catch it. A failing listener is logged in debug mode and does not stop the others.
Parameters
- $eventName : string
- $data : mixed = []
logError()
private
logError(string $message, Throwable $e) : void
Parameters
- $message : string
- $e : Throwable