forked from CodelyTV/php-ddd-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SymfonySyncEventBus.php
executable file
·35 lines (29 loc) · 999 Bytes
/
SymfonySyncEventBus.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
declare(strict_types = 1);
namespace CodelyTv\Shared\Infrastructure\Bus\Event;
use CodelyTv\Shared\Domain\Bus\Event\DomainEvent;
use CodelyTv\Shared\Domain\Bus\Event\EventBus;
use CodelyTv\Shared\Infrastructure\Symfony\Bundle\DependencyInjection\Compiler\CallableFirstParameterExtractor;
use Symfony\Component\Messenger\Handler\HandlersLocator;
use Symfony\Component\Messenger\MessageBus;
use Symfony\Component\Messenger\Middleware\HandleMessageMiddleware;
class SymfonySyncEventBus implements EventBus
{
private $bus;
public function __construct(iterable $subscribers)
{
$this->bus = new MessageBus(
[
new HandleMessageMiddleware(
new HandlersLocator(
CallableFirstParameterExtractor::forPipedCallables($subscribers)
)
),
]
);
}
public function notify(DomainEvent $event): void
{
$this->bus->dispatch($event);
}
}