Skip to content

Commit 513dcbb

Browse files
author
Olivier Laurendeau
authored
Merge pull request #8 from olaurendeau/feature/one-define-to-rule-all-vhosts
Command define all configured vhost, not just default one but still specified one
2 parents 20bd8e0 + c52dcff commit 513dcbb

File tree

5 files changed

+270
-537
lines changed

5 files changed

+270
-537
lines changed

Command/VhostDefineCommand.php

+34-32
Original file line numberDiff line numberDiff line change
@@ -29,59 +29,61 @@ protected function configure()
2929
*/
3030
protected function execute(InputInterface $input, OutputInterface $output)
3131
{
32-
try {
33-
$this->comment($input, $output, sprintf(
34-
'Define rabbitmq <info>%s</info> vhost configuration',
35-
$this->getVhost($input)
36-
));
37-
38-
$vhostConfiguration = $this->getVhostConfiguration($input);
39-
$vhostHandler = $this->getContainer()->get('ola_rabbit_mq_admin_toolkit.handler.vhost');
40-
$creation = !$vhostHandler->exists($vhostConfiguration);
41-
42-
$vhostHandler->define($vhostConfiguration);
43-
44-
$this->success($input, $output, sprintf(
45-
'Rabbitmq "%s" vhost configuration successfully %s !',
46-
$this->getVhost($input),
47-
$creation ? 'created' : 'updated'
48-
));
49-
} catch (\Exception $e) {
50-
if (!$this->getContainer()->getParameter('ola_rabbit_mq_admin_toolkit.silent_failure')) {
51-
throw $e;
32+
$vhostList = $this->getVhostList($input);
33+
34+
foreach ($vhostList as $vhost) {
35+
try {
36+
$this->comment($input, $output, sprintf(
37+
'Define rabbitmq <info>%s</info> vhost configuration',
38+
$vhost
39+
));
40+
41+
$vhostConfiguration = $this->getVhostConfiguration($vhost);
42+
$vhostHandler = $this->getContainer()->get('ola_rabbit_mq_admin_toolkit.handler.vhost');
43+
$creation = !$vhostHandler->exists($vhostConfiguration);
44+
45+
$vhostHandler->define($vhostConfiguration);
46+
47+
$this->success($input, $output, sprintf(
48+
'Rabbitmq "%s" vhost configuration successfully %s !',
49+
$vhost,
50+
$creation ? 'created' : 'updated'
51+
));
52+
} catch (\Exception $e) {
53+
if (!$this->getContainer()->getParameter('ola_rabbit_mq_admin_toolkit.silent_failure')) {
54+
throw $e;
55+
}
5256
}
5357
}
5458
}
5559

5660
/**
57-
* Retrieve vhost's name to process
61+
* Return Vhosts to process
5862
*
5963
* @param InputInterface $input
6064
*
61-
* @return string
65+
* @return array
6266
*/
63-
private function getVhost(InputInterface $input)
67+
private function getVhostList(InputInterface $input)
6468
{
65-
$vhost = $input->getArgument('vhost');
66-
if (empty($vhost)) {
67-
$vhost = $this->getContainer()->getParameter('ola_rabbit_mq_admin_toolkit.default_vhost');
69+
$inputVhost = $input->getArgument('vhost');
70+
$vhostList = array($inputVhost);
71+
if (empty($inputVhost)) {
72+
$vhostList = $this->getContainer()->getParameter('ola_rabbit_mq_admin_toolkit.vhost_list');
6873
}
6974

70-
return $vhost;
75+
return $vhostList;
7176
}
7277

7378
/**
74-
* @param InputInterface $input
75-
* @param OutputInterface $output
79+
* @param string $vhost
7680
*
7781
* @return VhostConfiguration
7882
*
7983
* @throws \InvalidArgumentException
8084
*/
81-
private function getVhostConfiguration(InputInterface $input)
85+
private function getVhostConfiguration($vhost)
8286
{
83-
$vhost = $this->getVhost($input);
84-
8587
$serviceName = sprintf(
8688
OlaRabbitMqAdminToolkitExtension::VHOST_MANAGER_SERVICE_TEMPLATE,
8789
$vhost

DependencyInjection/OlaRabbitMqAdminToolkitExtension.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function load(array $configs, ContainerBuilder $container)
2828
$configuration = new Configuration();
2929
$config = $this->processConfiguration($configuration, $configs);
3030

31-
$container->setParameter(sprintf(self::PARAMETER_TEMPLATE, 'default_vhost'), $config['default_vhost']);
31+
$container->setParameter(sprintf(self::PARAMETER_TEMPLATE, 'vhost_list'), array_keys($config['vhosts']));
3232
$container->setParameter(sprintf(self::PARAMETER_TEMPLATE, 'silent_failure'), $config['silent_failure']);
3333

3434
$this->loadConnections($config['connections'], $container);

Tests/Command/VhostDefineCommandTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function setUp()
2727
$this->container = $this->prophesize('Symfony\Component\DependencyInjection\ContainerInterface');
2828
$this->container->get('ola_rabbit_mq_admin_toolkit.handler.vhost')->willReturn($this->handler->reveal());
2929
$this->container->getParameter('ola_rabbit_mq_admin_toolkit.silent_failure')->willReturn(false);
30-
$this->container->getParameter('ola_rabbit_mq_admin_toolkit.default_vhost')->willReturn('foo');
30+
$this->container->getParameter('ola_rabbit_mq_admin_toolkit.vhost_list')->willReturn(array('foo'));
3131

3232
$this->command = new VhostDefineCommand();
3333
$this->command->setApplication($this->application);

Tests/DependencyInjection/OlaRabbitMqAdminToolkitExtensionTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function test_load_successfull()
8484
));
8585
$this->assertContainerBuilderHasService('ola_rabbit_mq_admin_toolkit.connection.default');
8686
$this->assertContainerBuilderHasService('ola_rabbit_mq_admin_toolkit.configuration.test');
87-
$this->assertContainerBuilderHasParameter('ola_rabbit_mq_admin_toolkit.default_vhost');
87+
$this->assertContainerBuilderHasParameter('ola_rabbit_mq_admin_toolkit.vhost_list');
8888
}
8989

9090
public function dataProvider_load_failBecauseModulusIsImproperlyDefined()

0 commit comments

Comments
 (0)