Event

Event is a synchronous, in-process dispatcher — no queue, no message bus. Listeners run immediately, in registration order, on the same request that dispatched the event.

Methods

Event::listen(string $name, callable $listener): void
Event::dispatch(string $name, mixed $payload = null): void
Event::hasListeners(string $name): bool
Event::forget(?string $name = null): void // clears one name, or every listener if omitted
Event::listen(Event::USER_REGISTERED, function (array $payload) {
    // e.g. queue a welcome email — synchronously, right here
});

Event::dispatch(Event::USER_REGISTERED, ['email' => $email]);

Built-in event names

Not restricted to these — dispatch and listen for your own event names too. The built-ins Clarity itself fires:

  • Event::LOGIN_SUCCESS / LOGIN_FAILED — from Authentication.
  • Event::USER_REGISTERED
  • Event::FILE_UPLOADED — from Files::store().
  • Event::MIGRATION_COMPLETED — from Migration::migrate(), once per newly-applied file.

Next steps

  • Files — dispatches FILE_UPLOADED.
  • Migration — dispatches MIGRATION_COMPLETED.