Skip to content

mleko/narrator

Repository files navigation

narrator/narrator

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.

Installation

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
$eventBus->emit($event);

Testing

To run unit tests use PHPUnit

$ ./vendor/bin/phpunit

About

Event library

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages