Skip to content

An immutable implementation of the PSR-14 (event-dispatcher) for ReactiveX PHP.

Notifications You must be signed in to change notification settings

Th3Mouk/reactive-event-dispatcher

Repository files navigation

Reactive Event Dispatcher // PSR-14

This PHP library provide an immutable implementation of the PSR-14 for ReactiveX PHP.

Latest Stable Version Latest Unstable Version Total Downloads License

Coverage Status Scrutinizer Code Quality

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.

About

An immutable implementation of the PSR-14 (event-dispatcher) for ReactiveX PHP.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published