smoren / event-router
Router for flexible configuring of event handling behaviors
v0.3.1
2022-12-23 11:45 UTC
Requires
- php: >=7.4.0
- smoren/extended-exceptions: ^1.0.0
Requires (Dev)
- codeception/codeception: ^4.2.1
- codeception/module-asserts: ^2.0
- php-coveralls/php-coveralls: ^2.0
- phpstan/phpstan: ^1.8
- smoren/nested-accessor: ^0.1.6
- squizlabs/php_codesniffer: 3.*
README
Router for flexible configuring of event handling behaviors.
How to install to your project
composer require smoren/event-router
Unit testing
composer install
composer test-init
composer test
Usage
use Smoren\EventRouter\Components\EventRouter; use Smoren\EventRouter\Interfaces\EventInterface; use Smoren\EventRouter\Events\Event; use Smoren\EventRouter\Structs\EventConfig; use Smoren\EventRouter\Loggers\ArrayLogger; $router = new EventRouter(10, new ArrayLogger()); $router ->on(new EventConfig('origin1'), function(EventInterface $event) { return null; }) ->on(new EventConfig('origin1', 'recursive_single'), function(EventInterface $event) { return new Event('origin2', 'test'); }) ->on(new EventConfig('origin1', 'recursive_multiple'), function(EventInterface $event) { return [ new Event('origin1', 'recursive_single'), new Event('origin2', 'test'), ]; }) ->on(new EventConfig('origin2'), function(EventInterface $event) { return null; }); $router->send(new Event('origin1', 'first'));