Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
9 / 9 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| SyncEventBus | |
100.00% |
9 / 9 |
|
100.00% |
3 / 3 |
3 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| dispatch | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 | |||
| subscribe | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | // ╔════════════════════════════════════════════════════════════╗ |
| 4 | // ║ MIT Licence (#Expat) - https://opensource.org/licenses/MIT ║ |
| 5 | // ║ Copyright 2026 Frederic Poeydomenge <dyno@phexium.com> ║ |
| 6 | // ╚════════════════════════════════════════════════════════════╝ |
| 7 | |
| 8 | declare(strict_types=1); |
| 9 | |
| 10 | namespace Phexium\Plugin\EventBus\Adapter; |
| 11 | |
| 12 | use Override; |
| 13 | use Phexium\Domain\Event\DomainEventInterface; |
| 14 | use Phexium\Plugin\Dispatcher\Port\DispatcherInterface; |
| 15 | use Phexium\Plugin\Dispatcher\Port\ListenerRegistryInterface; |
| 16 | use Phexium\Plugin\EventBus\Port\EventBusInterface; |
| 17 | use Phexium\Plugin\Logger\Port\LoggerInterface; |
| 18 | |
| 19 | final readonly class SyncEventBus implements EventBusInterface |
| 20 | { |
| 21 | public function __construct( |
| 22 | private DispatcherInterface $dispatcher, |
| 23 | private ListenerRegistryInterface $listenerRegistry, |
| 24 | private LoggerInterface $logger, |
| 25 | ) {} |
| 26 | |
| 27 | #[Override] |
| 28 | public function dispatch(DomainEventInterface $event): DomainEventInterface |
| 29 | { |
| 30 | $this->logger->debug('EventBus: Dispatching domain event', [ |
| 31 | 'event' => $event::class, |
| 32 | 'eventName' => $event->getEventName(), |
| 33 | 'aggregateId' => $event->getAggregateId()->getValue(), |
| 34 | ]); |
| 35 | |
| 36 | $this->dispatcher->dispatch($event); |
| 37 | |
| 38 | return $event; |
| 39 | } |
| 40 | |
| 41 | #[Override] |
| 42 | public function subscribe(string $event, callable $listener): void |
| 43 | { |
| 44 | $this->listenerRegistry->subscribeTo($event, $listener); |
| 45 | } |
| 46 | } |