pleets/php-event-dispatcher
Composer 安装命令:
composer require pleets/php-event-dispatcher
包简介
PSR-14 Event Dispatcher
关键字:
README 文档
README
Event Dispatching is a common and well-tested mechanism to allow developers to inject logic into an application easily and consistently. This library was developed according to PSR-14 and all interfaces in psr/event-dispatcher were implemented.
You can download this project as follows.
git clone git@github.com:pleets/php-event-dispatcher.git
Usage
Creating Events
An Event is a message produced by an Emitter. It may be any arbitrary PHP object.
You can create an event extending the Event class.
use Pleets\EventDispatcher\Event; class DepositEvent extends Event { public string $text; protected string $amount; private string $currency = 'USD'; public function __construct($amount) { $this->amount = $amount; $this->text = 'We are preparing your deposit: '.$this->amount.$this->currency; } }
Creating Listeners
A Listener is any PHP callable that expects to be passed an Event. Zero or more Listeners may be passed the same Event.
A Listener MAY enqueue some other asynchronous behavior if it so chooses.
You can create a listener extending the Listener class.
use Pleets\EventDispatcher\Event; use Pleets\EventDispatcher\Listener; class SendDepositNotification extends Listener { public function handle(Event $event): void { $event->text = 'Your deposit was done!'; } }
Creating Listener Providers and subscribing events
A Listener Provider is responsible for determining what Listeners are relevant for a given Event, but MUST NOT call the Listeners itself. A Listener Provider may specify zero or more relevant Listeners. You can create a listener provider as follows.
$provider = new ListenerProvider(); $deposit = new DepositEvent('127.00'); $provider->subscribe($deposit, new SendDepositNotification());
Dispatching your events
A Dispatcher is a service object that is given an Event object by an Emitter. The Dispatcher is responsible for ensuring that the Event is passed to all relevant Listeners, but MUST defer determining the responsible listeners to a Listener Provider. You can dispatch you events as follows.
$dispatcher = new Dispatcher($provider); $dispatcher->dispatch($deposit);
All listeners will be informed about this event and will be executed.
pleets/php-event-dispatcher 适用场景与选型建议
pleets/php-event-dispatcher 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 109 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 07 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「event dispatcher」 「psr-14」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 pleets/php-event-dispatcher 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 pleets/php-event-dispatcher 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 pleets/php-event-dispatcher 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Package that provides an integration with Doctrine ORM to automatically dispatch Domain Events.
Event dispatcher package
Symfony bundle for broadway/broadway.
This is an Event Emitter equivalent to Node.js' Event Emitter.
Publish / Subscribe / Event Manager
A PHP library to implement the observer pattern
统计信息
- 总下载量: 109
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-07-28