Skip to content

Commit

Permalink
Add basic usage to readme
Browse files Browse the repository at this point in the history
  • Loading branch information
mleko committed Nov 26, 2016
1 parent 25578b8 commit 10f1d30
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,52 @@
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/mleko/narrator/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/mleko/narrator/?branch=master)
[![Code Coverage](https://scrutinizer-ci.com/g/mleko/narrator/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/mleko/narrator/?branch=master)

Small and simple Event Bus library.

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

##Installation

Using [Composer](http://getcomposer.org/):

```sh
$ composer require narrator/narrator
```

##Basic usage

```php
// 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 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
```

0 comments on commit 10f1d30

Please sign in to comment.