1 | <?php |
||
13 | class RabbitMqManagerExtension extends Extension implements PrependExtensionInterface |
||
14 | { |
||
15 | /** |
||
16 | * @inheritdoc |
||
17 | */ |
||
18 | 4 | public function load(array $configs, ContainerBuilder $container) |
|
19 | { |
||
20 | 4 | $configuration = new Configuration(); |
|
21 | 4 | $config = $this->processConfiguration($configuration, $configs); |
|
22 | |||
23 | 4 | $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
|
24 | 4 | $loader->load('services.yml'); |
|
25 | |||
26 | $configuration = [ |
||
27 | 1 | 'path' => $config['path'], |
|
28 | 1 | 'consumers' => [], |
|
29 | 1 | 'rpc_servers' => [], |
|
30 | 1 | ]; |
|
31 | |||
32 | 1 | $rabbitMqBundleConfiguration = $container->getParameter('mos_old_sound_rabbit_mq.config'); |
|
33 | |||
34 | 1 | foreach (['consumers', 'rpc_servers'] as $type) { |
|
35 | 1 | if (isset($rabbitMqBundleConfiguration[$type])) { |
|
36 | 1 | foreach ($rabbitMqBundleConfiguration[$type] as $name => $consumer) { |
|
37 | 1 | $consumerConfig = isset($config[$type]['individual'][$name]) ? |
|
38 | 1 | $config[$type]['individual'][$name] : |
|
39 | 1 | $config[$type]['general']; |
|
40 | |||
41 | 1 | $command = $config['commands'][$type]; |
|
42 | |||
43 | 1 | if ('consumers' === $type && 'cli-consumer' === $consumerConfig['processor']) { |
|
44 | $command = $config['commands']['cli_consumer_invoker']; |
||
45 | } |
||
46 | |||
47 | 1 | $configuration[$type][$name] = $this->generateConfiguration( |
|
48 | 1 | $container, |
|
49 | 1 | $name, |
|
50 | 1 | $command, |
|
51 | 1 | $consumerConfig, |
|
52 | $consumer |
||
53 | 1 | ); |
|
54 | } |
||
55 | } |
||
56 | } |
||
57 | |||
58 | $container->setParameter('mos_rabbitmq_cli_consumer.config', $configuration); |
||
59 | $container->setParameter('mos_rabbitmq_cli_consumer.path', $configuration['path']); |
||
60 | } |
||
61 | |||
62 | /** |
||
63 | * @inheritdoc |
||
64 | */ |
||
65 | 2 | public function prepend(ContainerBuilder $container) |
|
78 | |||
79 | /** |
||
80 | * @param ContainerInterface $container |
||
81 | * @param string $name |
||
82 | * @param string $command |
||
83 | * @param array $config |
||
84 | * @param array $consumer |
||
85 | * |
||
86 | * @return array |
||
87 | */ |
||
88 | 1 | private function generateConfiguration(ContainerInterface $container, $name, $command, array $config, array $consumer) |
|
138 | |||
139 | /** |
||
140 | * @param ContainerInterface $container |
||
141 | * @param array $consumer |
||
142 | * |
||
143 | * @return array |
||
144 | * |
||
145 | * @throws InvalidConfigurationException |
||
146 | */ |
||
147 | 1 | private function getConnection(ContainerInterface $container, array $consumer) |
|
162 | } |
||
163 |