Switon's PSR-14 event package for application dispatch, listener discovery, and event logging.
- Wildcard listeners: one listener can handle every event with
object. - Attribute-based listeners:
#[EventListener]registers listener methods. - Automatic listener discovery: app scan paths and
extra.switon.listenersentries are included. - Event log level: events can carry a default PSR-3 level.
- Early-stop support: listeners can halt the remaining chain when needed.
- Automatic event logging: events can be logged automatically with structured output.
composer require switon/eventuse Psr\EventDispatcher\EventDispatcherInterface;
use Switon\Core\Attribute\Autowired;
use Switon\Eventing\Attribute\EventListener;
final class UserRegistered
{
public function __construct(public int $userId, public string $email)
{
}
}
class UserService
{
#[Autowired] protected EventDispatcherInterface $eventDispatcher;
public function register(string $email): void
{
$this->eventDispatcher->dispatch(new UserRegistered(123, $email));
}
}
class UserListener
{
#[EventListener]
public function onUserRegistered(UserRegistered $event): void
{
// react to the event
}
}Docs: https://docs.switon.dev/latest/event
MIT.