yiiboot / event-dispatcher
yii event dispatcher
Fund package maintenance!
Opencollective
yiiboot
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-11-11 20:21:24 UTC
README
Yii Boot Event Dispatcher
An way to define an event listener with the AsEventListener PHP attribute. This allows to configure the listener inside its class, without having to add any configuration in external files
Requirements
- PHP 8.1 or higher.
Installation
The package could be installed with composer:
composer require yiiboot/event-dispatcher
General usage
the config/params.php
return [ // ... 'yiiboot/attributed' => [ 'paths' => [ // ... dirname(__DIR__) . '/src/EventListener', ] ] ];
the 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 { // ... } }
Testing
Unit testing
The package is tested with PHPUnit. To run tests:
./vendor/bin/phpunit
Mutation testing
The package tests are checked with Infection mutation framework with Infection Static Analysis Plugin. To run it:
./vendor/bin/roave-infection-static-analysis-plugin
Static analysis
The code is statically analyzed with Psalm. To run static analysis:
./vendor/bin/psalm
Code style
Use Rector to make codebase follow some specific rules or use either newest or any specific version of PHP:
./vendor/bin/rector
Dependencies
Use ComposerRequireChecker to detect transitive Composer dependencies.
License
The Yii Boot Event Dispatcher is free software. It is released under the terms of the Apache-2.0 License.
Please see LICENSE
for more information.
Maintained by Yii Boot.