|
1
|
|
|
<?php declare(strict_types = 1); |
|
2
|
|
|
|
|
3
|
|
|
namespace TomCizek\SymfonyProoph\ServiceBus\ServiceBusConfigurators; |
|
4
|
|
|
|
|
5
|
|
|
use Prooph\Common\Messaging\MessageFactory; |
|
6
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
|
7
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
8
|
|
|
use TomCizek\SymfonyProoph\Common\DefaultConfigurator; |
|
9
|
|
|
|
|
10
|
|
|
abstract class AbstractBusConfigurator extends DefaultConfigurator |
|
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
|
18 |
|
public function buildDefaultConfig(): array |
|
23
|
|
|
{ |
|
24
|
|
|
return [ |
|
25
|
18 |
|
self::KEY_BUS_PLUGINS => [], |
|
26
|
18 |
|
self::KEY_BUS_ROUTER => [ |
|
27
|
18 |
|
self::KEY_BUS_ROUTER_ROUTES => [], |
|
28
|
|
|
], |
|
29
|
18 |
|
self::KEY_ENABLE_HANDLER_LOCATION => true, |
|
30
|
18 |
|
self::KEY_MESSAGE_FACTORY => MessageFactory::class, |
|
31
|
|
|
]; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
16 |
|
public function configureWithConfig(array $config): void |
|
35
|
|
|
{ |
|
36
|
16 |
|
$interopContainerServiceId = $this->getInteropContainerServiceId(); |
|
37
|
|
|
|
|
38
|
16 |
|
$factory = $this->getBusFactoryClass(); |
|
39
|
|
|
|
|
40
|
16 |
|
$serviceBusDefinition = new Definition($this->getBusClass()); |
|
41
|
|
|
|
|
42
|
|
|
$serviceBusDefinition |
|
43
|
16 |
|
->setFactory($factory . '::' . $this->getConfigKey()) |
|
44
|
16 |
|
->addArgument( |
|
45
|
16 |
|
new Reference($interopContainerServiceId) |
|
46
|
|
|
); |
|
47
|
|
|
|
|
48
|
16 |
|
$serviceBusDefinitionName = 'prooph.service_bus.' . $this->getConfigKey(); |
|
49
|
|
|
|
|
50
|
16 |
|
$this->containerBuilder->setDefinition($serviceBusDefinitionName, $serviceBusDefinition); |
|
51
|
16 |
|
$this->containerBuilder->setAlias($this->getBusClass(), $serviceBusDefinitionName); |
|
52
|
16 |
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|