This package is abandoned and no longer maintained. No replacement package was suggested.

A PHP Library

v0.2.1 2019-01-12 15:34 UTC

This package is auto-updated.

Last update: 2020-02-12 17:59:59 UTC


README

Scrutinizer Code Quality Code Coverage Build Status

Why ?

In order to improve my skills, I'm doing my own implementation of an EventBus.

Installation

composer require blacksmith-project/event-bus

How to use it ?

  • Your events need to implement the empty interface \BSP\Event
  • Your listeners need to implement the interface \BSP\EventListener
  • Extends \BSP\EventBus and add in your constructor the listeners.

Please note that there may be multiple listeners to a single event.

You can look for example in the tests/Mock folder.

Now, you only need to inject your EventBus and send Events.

Example:

public function __construct(EventBus $eventBus)
{
    $this->eventBus = $eventBus
}

public function handle(DoSomething $doSomething): void
{
    // do business logic

    $event = new SomethingDone();

    $this->eventBus->send($event);
}