EventDispatcher
Reference implementation of {@see MilpaEventDispatcherInterface}. Central hub for string-named, event-driven communication between plugins: exact and dot-segment wildcard subscriptions, priority ordering, listener error isolation (a throwing handler is logged and does not stop the rest), and a pluggable async (queue) seam — see {@see setAsyncDispatcher()} and the `$async` semantics documented on {@see dispatch()}.
EventDispatcher::__construct()
public function __construct(Psr\Log\LoggerInterface $logger):Parameters
| Name | Type | Description |
|---|---|---|
| $logger | Psr\Log\LoggerInterface |
EventDispatcher::setAsyncDispatcher()
public function setAsyncDispatcher(callable $dispatcher): voidWire the async dispatcher (typically a queue service) that `dispatch(..., async: true)` hands events to. Without this call, `$async=true` degrades to synchronous dispatch — see the `$async` semantics on {@see dispatch()}.
Parameters
| Name | Type | Description |
|---|---|---|
| $dispatcher | callable | fn(string $eventName, array $payload): void |
EventDispatcher::dispatch()
public function dispatch(string $eventName, array $payload = [], bool $async = false): void{@inheritdoc} `$async` semantics for this implementation, per the MAY/MUST contract on {@see MilpaEventDispatcherInterface::dispatch()}: with an async dispatcher wired via {@see setAsyncDispatcher()}, `$async=true` hands the event to that callable instead of invoking subscribers inline — a conformant queue dispatch, not a fallback. Without one wired, `$async=true` degrades to synchronous dispatch (subscribers run inline, in the same call) — a conformant MAY fallback, never a silent drop; the event is always either queued or run.
Parameters
| Name | Type | Description |
|---|---|---|
| $eventName | string | |
| $payload | array | |
| $async | bool |
EventDispatcher::subscribe()
public function subscribe(string $eventName, callable $handler, int $priority = 0): void{@inheritdoc}
Parameters
| Name | Type | Description |
|---|---|---|
| $eventName | string | |
| $handler | callable | |
| $priority | int |
EventDispatcher::getSubscribers()
public function getSubscribers(string $eventName): array{@inheritdoc}
Parameters
| Name | Type | Description |
|---|---|---|
| $eventName | string |
EventDispatcher::hasSubscribers()
public function hasSubscribers(string $eventName): bool{@inheritdoc}
Parameters
| Name | Type | Description |
|---|---|---|
| $eventName | string |
EventDispatcher::getRegisteredPatterns()
public function getRegisteredPatterns(): arrayGet all registered event patterns (for debugging).