From e04c19a819496223c3a21bb110fac9aacd19833c Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 31 Aug 2015 09:28:42 +0200 Subject: [PATCH] CommandForm: Use the CommandTransport class directly Provides a fallback mechanism now and will check the instance's name soon. refs #8981 refs #9651 --- .../application/forms/Command/CommandForm.php | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/modules/monitoring/application/forms/Command/CommandForm.php b/modules/monitoring/application/forms/Command/CommandForm.php index 162e4370c..19aead6ec 100644 --- a/modules/monitoring/application/forms/Command/CommandForm.php +++ b/modules/monitoring/application/forms/Command/CommandForm.php @@ -3,10 +3,12 @@ namespace Icinga\Module\Monitoring\Forms\Command; -use Icinga\Module\Monitoring\Backend\MonitoringBackend; -use Icinga\Module\Monitoring\Command\Transport\CommandTransport; +use Icinga\Exception\ConfigurationError; use Icinga\Web\Form; use Icinga\Web\Request; +use Icinga\Module\Monitoring\Backend\MonitoringBackend; +use Icinga\Module\Monitoring\Command\Transport\CommandTransport; +use Icinga\Module\Monitoring\Command\Transport\CommandTransportInterface; /** * Base class for command forms @@ -46,18 +48,28 @@ abstract class CommandForm extends Form /** * Get the transport used to send commands * - * @param Request $request + * @param Request $request * - * @return \Icinga\Module\Monitoring\Command\Transport\CommandTransportInterface + * @return CommandTransportInterface + * + * @throws ConfigurationError */ public function getTransport(Request $request) { - $transportName = $request->getParam('transport'); - if ($transportName !== null) { - $transport = CommandTransport::create($transportName); + if (($transportName = $request->getParam('transport')) !== null) { + $config = CommandTransport::getConfig(); + if ($config->hasSection($transportName)) { + $transport = CommandTransport::createTransport($config->getSection($transportName)); + } else { + throw new ConfigurationError(sprintf( + mt('monitoring', 'Command transport "%s" not found.'), + $transportName + )); + } } else { - $transport = CommandTransport::first(); + $transport = new CommandTransport(); } + return $transport; } }