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— fromAuthentication.Event::USER_REGISTEREDEvent::FILE_UPLOADED— fromFiles::store().Event::MIGRATION_COMPLETED— fromMigration::migrate(), once per newly-applied file.