Event
The Event package lets one part of an application react to something that happened in another part, without the two knowing about each other.
Say a user signs up. The code that creates the account should not also have to know about the welcome email, the audit log and the analytics call. With events, it announces user.registered once, and each of those reactions listens for it on its own:
php
event()->dispatch('user.registered', ['user' => $user]);The framework uses the same mechanism around each request and command: you can listen to web.send.before, console.command.before and similar events to run code at a fixed point of the run. See Hooking into the running app.
Package shape
Quantum\Event\EventManagerstores listeners and dispatches eventsQuantum\Event\Helpers\event.phpexposes the sharedevent()helperQuantum\Event\Exceptions\EventExceptionreports an empty event name
What to expect
- Any name works. Event names do not need to be declared anywhere; dispatching a name nobody listens to does nothing.
- Listeners stay. A listener runs on every dispatch of its event, not only the first.
- In order, right away. Listeners run synchronously, in the order they were registered, inside the
dispatch()call. - One payload array. Each listener receives the array passed to
dispatch(), or an empty array. - Errors are not caught. An exception thrown by a listener stops the dispatch and reaches the caller.
What the package does not do
- no listener priorities or wildcard names
- no return values collected from listeners
- no way to remove a listener once registered
- no queued or asynchronous delivery
