Services
EventsServiceInterface
v1.0.0In-process pub/sub event bus for cross-module notifications and one-off events.
Access
$ctx->events()?->emit('reports.refreshed', ['count' => 12]);How To Use It
- Use it for in-process coordination between Meteorack modules instead of hand-rolled global callbacks.
- Keep payloads small and explicit so listeners can evolve independently and unsubscribe cleanly when needed.
Works Well With
Methods
public function emit(string $event, array $payload = []): voidPublishes an event with an optional payload.
public function on(string $event, callable $listener): callableRegisters a listener and returns an unsubscribe callable.
public function once(string $event, callable $listener): voidRegisters a listener that runs only once.
Example
bootstrap.php
public function onSdkReady(SdkContext $ctx): void
{
parent::onSdkReady($ctx);
$ctx->events()?->on('billing.invoice_paid', [$this, 'refreshMetrics']);
}
public function refreshMetrics(array $payload): void
{
$this->getSdkContext()->logger()->info('reports.metrics_refreshed', $payload);
}