MilpaEventDispatcherInterface
Event Dispatcher Interface Enables plugins to emit and subscribe to events in a loosely-coupled manner.
MilpaEventDispatcherInterface::dispatch()
abstract public function dispatch(string $eventName, array $payload = [], bool $async = false): voidDispatch an event to all registered subscribers (exact-match plus any matching wildcard subscriptions), in descending priority order. Listener error isolation: if a handler throws, the dispatcher logs the error and continues to the remaining handlers — one failing listener MUST NOT abort the dispatch or prevent later listeners from running. (An implementation that needs fail-fast semantics must document the deviation.)
Parameters
| Nombre | Tipo | Descripción |
|---|---|---|
| $eventName | string | Event name (e.g., 'user.registered', 'order.shipped') |
| $payload | array<string, mixed> | Data to pass to handlers |
| $async | bool | If true, dispatch via queue for deferred execution |
MilpaEventDispatcherInterface::subscribe()
abstract public function subscribe(string $eventName, callable $handler, int $priority = 0): voidSubscribe a handler to an event name or a wildcard pattern. Wildcard grammar: event names are dot-separated segments; `*` matches exactly ONE segment (it does not span a `.`). Matching is case-sensitive and anchored (the whole name must match). Examples: `user.*` matches `user.created`/`user.deleted` but NOT `user.profile.updated`; `*.created` matches `user.created`/`order.created`; `*` alone matches only single-segment names (e.g. `boot`), not dotted ones.
Parameters
| Nombre | Tipo | Descripción |
|---|---|---|
| $eventName | string | Event name or wildcard pattern (e.g. 'user.created', 'user.*') |
| $handler | callable | Handler function: fn(string $event, array $payload): void |
| $priority | int | Higher priority handlers execute first (default: 0) |
MilpaEventDispatcherInterface::getSubscribers()
abstract public function getSubscribers(string $eventName): arrayGet all subscribers for an event (including wildcard matches).
Parameters
| Nombre | Tipo | Descripción |
|---|---|---|
| $eventName | string | Event name |
Returns
Array of handlers sorted by priority
MilpaEventDispatcherInterface::hasSubscribers()
abstract public function hasSubscribers(string $eventName): boolCheck if an event has any subscribers.
Parameters
| Nombre | Tipo | Descripción |
|---|---|---|
| $eventName | string | Event name |