switon/event
Composer 安装命令:
composer require switon/event
包简介
Class-based synchronous PSR-14 dispatch with attribute-discovered listeners for Switon Framework
README 文档
README
Switon's PSR-14 event package for application dispatch, listener discovery, and event logging.
Highlights
- 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.
Installation
composer require switon/event
Quick Start
use 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
License
MIT.
统计信息
- 总下载量: 76
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 31
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-06-07