th3mouk / reactive-event-dispatcher
An immutable implementation of the PSR-14 (event-dispatcher) for ReactiveX PHP.
0.1.0
2021-10-28 20:39 UTC
Requires
- php: >=7.4
- psr/container: ^1.0
- psr/event-dispatcher: ^1.0
- reactivex/rxphp: ^2.0
Requires (Dev)
- phpstan/phpstan: ^0.12.99
- phpunit/phpunit: ^9.5.10
- vimeo/psalm: ^3.18.2
- youdot/coding-standard: ^3.1.0
Suggests
- vimeo/psalm: Immutability is ensured by Psalm only to remove some boilerplate
README
This PHP library provide an immutable implementation of the PSR-14 for ReactiveX PHP.
Installation
composer require th3mouk/reactive-event-dispatcher
Usage
Psalm usage is recommended. See relative introduction and documentation.
use Psr\Container\ContainerInterface; use Rx\Observable; use Th3Mouk\ReactiveEventDispatcher\Dispatcher; use Th3Mouk\ReactiveEventDispatcher\Event; use Th3Mouk\ReactiveEventDispatcher\EventCorrelation; use Th3Mouk\ReactiveEventDispatcher\Listener; use Th3Mouk\ReactiveEventDispatcher\ListenerProvider; use Th3Mouk\ReactiveEventDispatcher\Priority; $event = new class implements Event {}; $listener = new class implements Listener { public function process (Event $event) : Observable { return Observable::of(1); } }; // Link between an event and a listener // Higher is the priority, earlier is the call $event_correlations = [ EventCorrelation::create( get_class($event), get_class($listener), Priority::fromInt(0), ) ]; // Any object implementing ContainerInterface // Listeners must be present into $locator = new class implements ContainerInterface{ public function get($id){ } public function has($id){ } }; $listener_provider = new ListenerProvider($locator, $event_correlations); $dispatcher = new Dispatcher($listener_provider); $dispatcher->dispatch($event)->subscribe();
Please
Feel free to improve this library.