PHP code example of th3mouk / reactive-event-dispatcher
1. Go to this page and download the library: Download th3mouk/reactive-event-dispatcher library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
th3mouk / reactive-event-dispatcher example snippets
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();