ewn/ovent
Composer 安装命令:
composer require ewn/ovent
包简介
An event system using a form of the observer design pattern.
README 文档
README
(wip)
Usage
Basic observation
Here A can only observe and B can only emit events
<?php use Ewn\Ovent\Interface\EventEmitterInterface; use Ewn\Ovent\Interface\EventObserverInterface; use Ewn\Ovent\Trait\EventEmitterTrait; use Ewn\Ovent\Trait\EventObserverTrait; use Ewn\Ovent\Event; class A implements EventObserverInterface { use EventObserverTrait; public function __construct() { $this->listenEvent('event-name', function (Event $event) { var_dump($event); }); } } class B implements EventEmitterInterface { use EventEmitterTrait; public function send(): void { $this->emitEvent('event-name'); } } $observer = new A; $emitter = new B; $observer->observeEmitter($emitter); // or $emitter->attachObserver($observer); $emitter->send();
Observing and Emitting from the same object
<?php use Ewn\Ovent\Attribute\BindTo; use Ewn\Ovent\Enum\Scope; use Ewn\Ovent\Event; use Ewn\Ovent\Interface\EventInterface; use Ewn\Ovent\Trait\EventTrait; class A implements EventInterface { use EventTrait; public string $public = 'is public'; private string $private = 'is private'; public function __construct() { $this->observeSelf(); } } $a = new A; // Does not have access to $this $a->listenEvent('event-1', function (Event $event) { echo 'From ', $event->name, PHP_EOL; }); // Does have access to $this, but only public properties. $a->listenEvent('event-2', #[BindTo(Scope::PUBLIC)] function (Event $event) { echo 'From ', $event->name, ' ', $this->public, PHP_EOL; }); // Has full access to $this. $a->listenEvent('event-3', #[BindTo(Scope::PRIVATE)] function (Event $event) { echo 'From ', $event->name, ' ', $this->private, PHP_EOL; }); $a->emitEvent('event-1'); $a->emitEvent('event-2'); $a->emitEvent('event-3');
Output:
From event-1
From event-2 is public
From event-3 is private
Updating and removing Listeners
<?php use Ewn\Ovent\Event; use Ewn\Ovent\Interface\EventInterface; use Ewn\Ovent\Trait\EventTrait; class A implements EventInterface { use EventTrait; public function __construct() { $this->observeSelf(); } } $a = new A; /** @var \Ewn\Ovent\Listener $listener */ $listener = $a->listenEvent('event-1', function (Event $event) { echo 'From ', $event->name, PHP_EOL; }); $a->emitEvent('event-1'); // > "From event-1" $listener->replaceCallback(function (Event $event) { echo 'Still form ', $event->name, PHP_EOL; }); $a->emitEvent('event-1'); // > "Still form event-1" $a->removeListener($listener);
ewn/ovent 适用场景与选型建议
ewn/ovent 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 23 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 01 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 ewn/ovent 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ewn/ovent 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 23
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 26
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-06