|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Ola\RabbitMqAdminToolkitBundle\DependencyInjection; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
6
|
|
|
use Symfony\Component\Config\FileLocator; |
|
7
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
|
8
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
9
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
|
10
|
|
|
use Symfony\Component\DependencyInjection\Loader; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* This is the class that loads and manages your bundle configuration |
|
14
|
|
|
* |
|
15
|
|
|
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html} |
|
16
|
|
|
*/ |
|
17
|
|
|
class OlaRabbitMqAdminToolkitExtension extends Extension |
|
18
|
|
|
{ |
|
19
|
|
|
const PARAMETER_TEMPLATE = 'ola_rabbit_mq_admin_toolkit.%s'; |
|
20
|
|
|
const CONNECTION_SERVICE_TEMPLATE = 'ola_rabbit_mq_admin_toolkit.connection.%s'; |
|
21
|
|
|
const VHOST_MANAGER_SERVICE_TEMPLATE = 'ola_rabbit_mq_admin_toolkit.configuration.%s'; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* {@inheritdoc} |
|
25
|
|
|
*/ |
|
26
|
1 |
|
public function load(array $configs, ContainerBuilder $container) |
|
27
|
|
|
{ |
|
28
|
1 |
|
$configuration = new Configuration(); |
|
29
|
1 |
|
$config = $this->processConfiguration($configuration, $configs); |
|
30
|
|
|
|
|
31
|
1 |
|
$container->setParameter(sprintf(self::PARAMETER_TEMPLATE, 'default_vhost'), $config['default_vhost']); |
|
32
|
|
|
|
|
33
|
1 |
|
$this->loadConnections($config['connections'], $container); |
|
34
|
1 |
|
$this->loadVhostManagers($config['vhosts'], $container, $config['delete_allowed']); |
|
35
|
|
|
|
|
36
|
1 |
|
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
|
37
|
1 |
|
$loader->load('services.xml'); |
|
38
|
1 |
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @param array $connections |
|
42
|
|
|
* @param ContainerBuilder $container |
|
43
|
|
|
*/ |
|
44
|
1 |
|
private function loadConnections(array $connections, ContainerBuilder $container) |
|
45
|
|
|
{ |
|
46
|
1 |
|
foreach ($connections as $name => $uri) { |
|
47
|
|
|
|
|
48
|
1 |
|
$parsedUri = parse_url($uri); |
|
49
|
|
|
|
|
50
|
1 |
|
$definition = new Definition('RabbitMq\ManagementApi\Client', array( |
|
51
|
1 |
|
null, |
|
52
|
1 |
|
sprintf("%s://%s:%s", $parsedUri['scheme'], $parsedUri['host'], $parsedUri['port']), |
|
53
|
1 |
|
$parsedUri['user'], |
|
54
|
1 |
|
$parsedUri['pass'] |
|
55
|
1 |
|
)); |
|
56
|
|
|
|
|
57
|
1 |
|
$container->setDefinition(sprintf(self::CONNECTION_SERVICE_TEMPLATE, $name), $definition); |
|
58
|
1 |
|
} |
|
59
|
1 |
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @param array $vhosts |
|
63
|
|
|
* @param ContainerBuilder $container |
|
64
|
|
|
* @param $deleteAllowed |
|
65
|
|
|
*/ |
|
66
|
1 |
|
private function loadVhostManagers(array $vhosts, ContainerBuilder $container, $deleteAllowed) |
|
67
|
|
|
{ |
|
68
|
1 |
|
foreach ($vhosts as $name => $vhost) { |
|
69
|
1 |
|
$definition = new Definition('Ola\RabbitMqAdminToolkitBundle\VhostConfiguration', array( |
|
70
|
1 |
|
new Reference(sprintf(self::CONNECTION_SERVICE_TEMPLATE, $vhost['connection'])), |
|
71
|
1 |
|
!empty($vhost['name']) ? $vhost['name'] : $name, |
|
72
|
1 |
|
$vhost, |
|
73
|
|
|
$deleteAllowed |
|
74
|
1 |
|
)); |
|
75
|
1 |
|
$container->setDefinition(sprintf(self::VHOST_MANAGER_SERVICE_TEMPLATE, $name), $definition); |
|
76
|
1 |
|
} |
|
77
|
1 |
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|