fig/event-dispatcher-util
Composer 安装命令:
composer require fig/event-dispatcher-util
包简介
Useful utility classes and traits for implementing the PSR events standard
README 文档
README
This package contains a series of traits and base classes to cover the common, boilerplate portions of implementing a PSR-14-compliant event dispatcher library.
Install
Via Composer
$ composer require fig/event-dispatcher-util
Usage
Aggregate provider
The AggregateProvider class is a ListenerProvider implementation that collects and concatenates other listener providers. It is a simple wrapper that yields from a series of configured providers, in order.
use Fig\EventDispatcher\AggregateProvider; $provider1 = new YourProvider(); $provider2 = new SomeOtherProvider(); $provider = (new AggregateProvider()) ->addProvider($provider1) ->addProvider($provider2) ; $dispatcher = new SomeDispatcher($provider);
The aggregate provider will now return all the listeners from YourProvider, followed by all the listeners from SomeOtherProvider.
Delegating provider
The DelegatingProvider is another multi-provider front-end. In this case, it can be configured such that certain event types will use one sub-provider, and others will use a different one. A given type can be configured with multiple sub-providers, and events will be matched using instanceof so that sub-classes of an event are also affected.
use Fig\EventDispatcher\DelegatingProvider; $requestProvider = new KernelListenerProvider(); $ormProvider = new OrmListenerProvider(); $defaultProvider = new SomeDefaultProvider(); // Assume HttpEvent and OrmEvent are interfaces for event classes. $provider = (new DelegatingProvider($defaultProvider)) ->addProvider($requestProvider, [HttpEvent::class]) ->addProvider($ormProvider, [OrmEvent::class]) ; $dispatcher = new SomeDispatcher($provider);
Now, events sent to the dispatcher that implement HttpEvent will be passed along to KernelListenerProvider only, while those that implement OrmEvent will be passed along to OrmListenerProvider only. Any other events will be passed on to the default provider only.
AggregateProvider and DelegateProvider are fully compatible with each other, so either can use an instance of the other as one of its sub-providers.
Parameter provider helpers
The ParameterDeriverTrait is a set of tools to help listener provider implementations with deriving the type of a callable's parameter, to know what type of event it is. PHP supports a wide variety of callable types, which are not always easy to disambiguate. The tools in this class help ease that process.
If you are not writing your own Provider registration mechanism, this trait will not be useful.
Testing
$ composer test
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security-related issues, please email one of the current PHP-FIG Secretaries instead of using the issue tracker.
License
This package is released under the MIT license. Please see License File for more information.
fig/event-dispatcher-util 适用场景与选型建议
fig/event-dispatcher-util 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 472.38k 次下载、GitHub Stars 达 27, 最近一次更新时间为 2018 年 09 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「events」 「psr-14」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 fig/event-dispatcher-util 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 fig/event-dispatcher-util 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 fig/event-dispatcher-util 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Библиотека для реализаций паттерна Pub/Sub
Wireless Cross-Component Communication
A powerful event calendar Tool for Laravel's Nova 5.
Command bus implementation: Commands and domain events
Lightweight PSR-14 event dispatcher for PHP 8.2+ with stable priority ordering, stoppable events, and optional container-aware resolution.
This is an Event Emitter equivalent to Node.js' Event Emitter.
统计信息
- 总下载量: 472.38k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 27
- 点击次数: 32
- 依赖项目数: 25
- 推荐数: 2
其他信息
- 授权协议: MIT
- 更新时间: 2018-09-27