1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace CultuurNet\UDB3\Offer; |
4
|
|
|
|
5
|
|
|
use Broadway\CommandHandling\CommandBusInterface; |
6
|
|
|
use Broadway\Domain\DomainMessage; |
7
|
|
|
use Broadway\EventHandling\EventListenerInterface; |
8
|
|
|
use CultuurNet\UDB3\Address\CultureFeedAddressFactoryInterface; |
9
|
|
|
use Psr\Log\LoggerInterface; |
10
|
|
|
|
11
|
|
|
abstract class AbstractGeoCoordinatesProcessManager implements EventListenerInterface |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var CommandBusInterface |
15
|
|
|
*/ |
16
|
|
|
protected $commandBus; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var CultureFeedAddressFactoryInterface |
20
|
|
|
*/ |
21
|
|
|
protected $addressFactory; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var LoggerInterface |
25
|
|
|
*/ |
26
|
|
|
protected $logger; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @param CommandBusInterface $commandBus |
30
|
|
|
* @param CultureFeedAddressFactoryInterface $addressFactory |
31
|
|
|
* @param LoggerInterface $logger |
32
|
|
|
*/ |
33
|
|
|
public function __construct( |
34
|
|
|
CommandBusInterface $commandBus, |
35
|
|
|
CultureFeedAddressFactoryInterface $addressFactory, |
36
|
|
|
LoggerInterface $logger |
37
|
|
|
) { |
38
|
|
|
$this->commandBus = $commandBus; |
39
|
|
|
$this->addressFactory = $addressFactory; |
40
|
|
|
$this->logger = $logger; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
protected abstract function getEventHandlers(); |
|
|
|
|
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param DomainMessage $domainMessage |
47
|
|
|
*/ |
48
|
|
|
public function handle(DomainMessage $domainMessage) |
49
|
|
|
{ |
50
|
|
|
$payload = $domainMessage->getPayload(); |
51
|
|
|
$className = get_class($payload); |
52
|
|
|
$eventHandlers = $this->getEventHandlers(); |
53
|
|
|
|
54
|
|
|
if (isset($eventHandlers[$className])) { |
55
|
|
|
$eventHandler = $eventHandlers[$className]; |
56
|
|
|
call_user_func([$this, $eventHandler], $payload); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
} |