Event library

v0.4 2017-03-20 18:44 UTC

This package is auto-updated.

Last update: 2020-12-30 02:10:10 UTC


Travis CI Scrutinizer Code Quality Code Coverage

Small and simple Event Bus library.

Narrator allows communication between components without requiring the component to explicitly depend on each other.


Using Composer:

$ composer require narrator/narrator

Basic usage

// Simple event object
class UserRegistered {
    private $userId;
    private $userName;
    // ...event data, constructor, getters
// Sample listener
class UserRegisteredListener implements Listener {

    public function handle($event, Meta $meta){
        // send email, update model, etc

// create EventBus which will be responsible for managing events and listeners
$eventBus = new BasicEventBus(new NameBasedResolver(new ClassNameExtractor()));

// create listener instance
$listener = new UserRegisteredListener(...);
// and register it in bus
$eventBus->subscribe(UserRegistered::class, $listener);

// create event
$event = new UserRegistered(...);
// and `emit` it to listeners


To run unit tests use PHPUnit

$ ./vendor/bin/phpunit