forked from GwendolenLynch/msgphp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDomainMessageBus.php
More file actions
31 lines (26 loc) · 801 Bytes
/
Copy pathDomainMessageBus.php
File metadata and controls
31 lines (26 loc) · 801 Bytes
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
<?php
declare(strict_types=1);
namespace MsgPhp\Domain\Message;
/**
* @author Roland Franssen <franssen.roland@gmail.com>
*/
final class DomainMessageBus implements DomainMessageBusInterface
{
private $commandBus;
private $eventBus;
private $eventClasses;
public function __construct(DomainMessageBusInterface $commandBus, DomainMessageBusInterface $eventBus, array $eventClasses)
{
$this->commandBus = $commandBus;
$this->eventBus = $eventBus;
$this->eventClasses = array_flip($eventClasses);
}
public function dispatch($message): void
{
if (isset($this->eventClasses[\get_class($message)])) {
$this->eventBus->dispatch($message);
} else {
$this->commandBus->dispatch($message);
}
}
}