yiiboot / event-dispatcher
yii 事件调度器
v1.0.0
2022-11-27 12:35 UTC
Requires
- php: ^8.1
- yiiboot/attributed: ^2.0
- yiisoft/arrays: ^2.1
- yiisoft/injector: ^1.1
- yiisoft/yii-event: ^1.0
Requires (Dev)
- phpunit/phpunit: ^9.5
- rector/rector: ^0.14.3
- roave/infection-static-analysis-plugin: ^1.16
- spatie/phpunit-watcher: ^1.23
- vimeo/psalm: ^4.18
This package is not auto-updated.
Last update: 2024-09-30 19:50:22 UTC
README
Yii Boot 事件调度器
使用 AsEventListener PHP 属性定义事件监听器的方法。这允许在类内部配置监听器,而无需在外部文件中添加任何配置
要求
- PHP 8.1 或更高版本。
安装
此包可以通过 composer 安装
composer require yiiboot/event-dispatcher
一般用法
在 config/params.php
return [ // ... 'yiiboot/attributed' => [ 'paths' => [ // ... dirname(__DIR__) . '/src/EventListener', ] ] ];
在 src/EventListener/MyMultiListener.php
namespace App\EventListener; use Yiiboot\EventDispatcher\Attribute\AsEventListener; #[AsEventListener(event: CustomEvent::class, method: 'onCustomEvent')] #[AsEventListener(event: FooEvent::class, priority: 42)] #[AsEventListener(method: 'onBarEvent', group: ['console', 'web'], env: 'prod')] final class MyMultiListener { public function onCustomEvent(CustomEvent $event): void { // ... } public function onFooEvent(FooEvent $event): void { // ... } public function onBarEvent(BarEvent $event): void { // ... } #[AsEventListener] public function onMethodEvent(BarEvent $event): void { // ... } }
测试
单元测试
此包使用 PHPUnit 进行测试。要运行测试
./vendor/bin/phpunit
突变测试
此包的测试使用 Infection 突变框架和 Infection 静态分析插件 进行检查。要运行它
./vendor/bin/roave-infection-static-analysis-plugin
静态分析
代码使用 Psalm 进行静态分析。要运行静态分析
./vendor/bin/psalm
代码风格
使用 Rector 使代码库遵循某些特定规则,或使用最新版或任何特定版本的 PHP
./vendor/bin/rector
依赖
使用 ComposerRequireChecker 检测 Composer 传递依赖。
许可
Yii Boot 事件调度器是自由软件。它根据 Apache-2.0 许可证的条款发布。有关更多信息,请参阅 LICENSE
由 Yii Boot 维护。