|
1
|
|
|
<?php declare(strict_types = 1); |
|
2
|
|
|
|
|
3
|
|
|
namespace LidskaSila\Prooph\ServiceBus\ServiceBusConfigurators; |
|
4
|
|
|
|
|
5
|
|
|
use LidskaSila\Prooph\Common\DefaultConfigurator; |
|
6
|
|
|
use Prooph\Common\Messaging\MessageFactory; |
|
7
|
|
|
use Prooph\ServiceBus\MessageBus; |
|
8
|
|
|
|
|
9
|
|
|
abstract class AbstractBusConfigurator extends DefaultConfigurator |
|
10
|
|
|
{ |
|
11
|
|
|
|
|
12
|
|
|
protected const KEY_BUS_PLUGINS = 'plugins'; |
|
13
|
|
|
protected const KEY_BUS_ROUTER = 'router'; |
|
14
|
|
|
protected const KEY_BUS_ROUTER_ROUTES = 'routes'; |
|
15
|
|
|
protected const KEY_ENABLE_HANDLER_LOCATION = 'enable_handler_location'; |
|
16
|
|
|
protected const KEY_MESSAGE_FACTORY = 'message_factory'; |
|
17
|
|
|
|
|
18
|
|
|
abstract public function getBusClass(): string; |
|
19
|
|
|
|
|
20
|
|
|
abstract public function getBusFactoryClass(): string; |
|
21
|
|
|
|
|
22
|
|
|
public function buildDefaultConfig(): array |
|
23
|
|
|
{ |
|
24
|
|
|
return [ |
|
25
|
|
|
self::KEY_BUS_PLUGINS => [], |
|
26
|
|
|
self::KEY_BUS_ROUTER => [ |
|
27
|
|
|
self::KEY_BUS_ROUTER_ROUTES => [], |
|
28
|
|
|
], |
|
29
|
|
|
self::KEY_ENABLE_HANDLER_LOCATION => true, |
|
30
|
|
|
self::KEY_MESSAGE_FACTORY => MessageFactory::class, |
|
31
|
|
|
]; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function loadConfiguration(array $config): void |
|
35
|
|
|
{ |
|
36
|
|
|
$containerWrapperServiceId = $this->getContainerWrapperServiceId(); |
|
37
|
|
|
|
|
38
|
|
|
$this |
|
|
|
|
|
|
39
|
|
|
->getContainerBuilder() |
|
40
|
|
|
->addDefinition($this->getBusServiceId()) |
|
41
|
|
|
->setClass($this->getBusClass()) |
|
42
|
|
|
->setFactory(static::class . '::create', [ $this->getBusFactoryClass(), $this->getConfigKey(), '@' . $containerWrapperServiceId ]); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public static function create($factory, $busConfigName, $containerWrapperService): MessageBus |
|
46
|
|
|
{ |
|
47
|
|
|
return $factory::$busConfigName($containerWrapperService); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
private function getBusServiceId(): string |
|
51
|
|
|
{ |
|
52
|
|
|
return $this->extension->prefix($this->getConfigKey()); |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|
This method has been deprecated.