1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace Eps\Req2CmdBundle\DependencyInjection; |
5
|
|
|
|
6
|
|
|
use Symfony\Component\Config\FileLocator; |
7
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
8
|
|
|
use Symfony\Component\DependencyInjection\Extension\Extension; |
9
|
|
|
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; |
10
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
11
|
|
|
|
12
|
|
|
final class Req2CmdExtension extends Extension |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* {@inheritdoc} |
16
|
|
|
* @throws \Exception |
17
|
|
|
*/ |
18
|
|
|
public function load(array $configs, ContainerBuilder $container): void |
19
|
|
|
{ |
20
|
|
|
$configuration = new Req2CmdConfiguration(); |
21
|
|
|
$config = $this->processConfiguration($configuration, $configs); |
22
|
|
|
|
23
|
|
|
$loader = new XmlFileLoader( |
24
|
|
|
$container, |
25
|
|
|
new FileLocator(__DIR__ . '/../Resources/config') |
26
|
|
|
); |
27
|
|
|
|
28
|
|
|
$loader->load('actions.xml'); |
29
|
|
|
$loader->load('extractors.xml'); |
30
|
|
|
$loader->load('listeners.xml'); |
31
|
|
|
$loader->load('param_mappers.xml'); |
32
|
|
|
$loader->load('command_bus.xml'); |
33
|
|
|
|
34
|
|
|
$this->configureExtractors($config, $container); |
35
|
|
|
$this->configureCommandBus($config, $container); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function getAlias(): string |
39
|
|
|
{ |
40
|
|
|
return 'req2cmd'; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
private function configureExtractors(array $config, ContainerBuilder $container): void |
44
|
|
|
{ |
45
|
|
|
$extractorId = (string)$config['extractor']['service_id']; |
46
|
|
|
$container->setAlias('eps.req2cmd.extractor', $extractorId); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
private function configureCommandBus(array $config, ContainerBuilder $container): void |
50
|
|
|
{ |
51
|
|
|
$commandBusId = (string)$config['command_bus']['service_id']; |
52
|
|
|
if ($commandBusId === 'eps.req2cmd.command_bus.tactician') { |
53
|
|
|
$busName = (string)$config['command_bus']['name']; |
54
|
|
|
$tacticianServiceName = 'tactician.commandbus.' . $busName; |
55
|
|
|
$busDefinition = $container->findDefinition('eps.req2cmd.command_bus.tactician'); |
56
|
|
|
$busDefinition->replaceArgument(0, new Reference($tacticianServiceName)); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
$container->setAlias('eps.req2cmd.command_bus', $commandBusId); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|