DomainEventBus.php
54 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AmeliaBooking\Domain\Events; |
| 4 | |
| 5 | use League\Event\Emitter; |
| 6 | |
| 7 | /** |
| 8 | * Wrapper for the League Event library to keep the domain independent of infrastructure |
| 9 | * Class DomainEventBus |
| 10 | * |
| 11 | * @package AmeliaBooking\Domain\Events |
| 12 | */ |
| 13 | class DomainEventBus |
| 14 | { |
| 15 | /** |
| 16 | * Implementation of event emitter |
| 17 | * |
| 18 | * @var Emitter $eventEmitter |
| 19 | */ |
| 20 | private $eventEmitter; |
| 21 | |
| 22 | /** |
| 23 | * Constructor with injection of event emitter implementation |
| 24 | * |
| 25 | * @param Emitter $eventEmitter |
| 26 | */ |
| 27 | public function __construct($eventEmitter) |
| 28 | { |
| 29 | $this->eventEmitter = $eventEmitter; |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Emitting the event through the Emitter |
| 34 | * |
| 35 | * @param $eventName |
| 36 | * @param $eventParams |
| 37 | */ |
| 38 | public function emit($eventName, $eventParams) |
| 39 | { |
| 40 | $this->eventEmitter->emit($eventName, $eventParams); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Adding an event listener |
| 45 | * |
| 46 | * @param $eventName |
| 47 | * @param $subscriber |
| 48 | */ |
| 49 | public function addListener($eventName, $subscriber) |
| 50 | { |
| 51 | $this->eventEmitter->addListener($eventName, $subscriber); |
| 52 | } |
| 53 | } |
| 54 |