|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types = 1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Innmind\AMQPBundle\DependencyInjection; |
|
5
|
|
|
|
|
6
|
|
|
use Symfony\Component\{ |
|
7
|
|
|
HttpKernel\DependencyInjection\Extension, |
|
8
|
|
|
DependencyInjection\ContainerBuilder, |
|
9
|
|
|
DependencyInjection\Loader, |
|
10
|
|
|
DependencyInjection\Reference, |
|
11
|
|
|
Config\FileLocator |
|
12
|
|
|
}; |
|
13
|
|
|
|
|
14
|
|
|
final class InnmindAMQPExtension extends Extension |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* {@inheritdoc} |
|
18
|
|
|
*/ |
|
19
|
4 |
|
public function load(array $configs, ContainerBuilder $container) |
|
20
|
|
|
{ |
|
21
|
4 |
|
$loader = new Loader\YamlFileLoader( |
|
22
|
4 |
|
$container, |
|
23
|
4 |
|
new FileLocator(__DIR__.'/../Resources/config') |
|
24
|
|
|
); |
|
25
|
4 |
|
$loader->load('services.yml'); |
|
26
|
4 |
|
$config = $this->processConfiguration( |
|
27
|
4 |
|
new Configuration, |
|
28
|
4 |
|
$configs |
|
29
|
|
|
); |
|
30
|
|
|
|
|
31
|
|
|
$container |
|
32
|
4 |
|
->getDefinition('innmind.amqp.connection.default') |
|
33
|
4 |
|
->replaceArgument(1, $config['server']) |
|
34
|
4 |
|
->replaceArgument(3, $config['server']['timeout']) |
|
35
|
4 |
|
->replaceArgument(4, new Reference($config['clock'])); |
|
36
|
|
|
|
|
37
|
4 |
|
$definition = $container->getDefinition('innmind.amqp.argument_translator'); |
|
38
|
|
|
|
|
39
|
4 |
|
foreach ($config['argument_translators'] as $translator) { |
|
40
|
|
|
$definition->addArgument(new Reference($translator)); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
4 |
|
$autoDeclare = $container->getDefinition('innmind.amqp.client.auto_declare'); |
|
44
|
4 |
|
$consumers = $container->getDefinition('innmind.amqp.consumers'); |
|
45
|
|
|
|
|
46
|
4 |
|
foreach ($config['exchanges'] as $name => $exchange) { |
|
47
|
4 |
|
$autoDeclare->addMethodCall( |
|
48
|
4 |
|
'declareExchange', |
|
49
|
4 |
|
[$name, $exchange['type'], $exchange['durable'], $exchange['arguments']] |
|
50
|
|
|
); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
4 |
|
foreach ($config['queues'] as $name => $queue) { |
|
54
|
4 |
|
$autoDeclare->addMethodCall( |
|
55
|
4 |
|
'declareQueue', |
|
56
|
4 |
|
[$name, $queue['durable'], $queue['exclusive'], $queue['arguments']] |
|
57
|
|
|
); |
|
58
|
4 |
|
$consumers->addMethodCall( |
|
59
|
4 |
|
'add', |
|
60
|
4 |
|
[$name, new Reference($queue['consumer'])] |
|
61
|
|
|
); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
4 |
|
foreach ($config['bindings'] as $binding) { |
|
65
|
4 |
|
$autoDeclare->addMethodCall( |
|
66
|
4 |
|
'declareBinding', |
|
67
|
4 |
|
[$binding['exchange'], $binding['queue'], $binding['routingKey'], $binding['arguments']] |
|
68
|
|
|
); |
|
69
|
|
|
} |
|
70
|
4 |
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|