CommandForm: Use the CommandTransport class directly

Provides a fallback mechanism now and will check the instance's
name soon.

refs #8981
refs #9651
This commit is contained in:
Johannes Meyer 2015-08-31 09:28:42 +02:00
parent fcbd24e28e
commit e04c19a819

View File

@ -3,10 +3,12 @@
namespace Icinga\Module\Monitoring\Forms\Command; namespace Icinga\Module\Monitoring\Forms\Command;
use Icinga\Module\Monitoring\Backend\MonitoringBackend; use Icinga\Exception\ConfigurationError;
use Icinga\Module\Monitoring\Command\Transport\CommandTransport;
use Icinga\Web\Form; use Icinga\Web\Form;
use Icinga\Web\Request; 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 * Base class for command forms
@ -48,16 +50,26 @@ abstract class CommandForm extends Form
* *
* @param Request $request * @param Request $request
* *
* @return \Icinga\Module\Monitoring\Command\Transport\CommandTransportInterface * @return CommandTransportInterface
*
* @throws ConfigurationError
*/ */
public function getTransport(Request $request) public function getTransport(Request $request)
{ {
$transportName = $request->getParam('transport'); if (($transportName = $request->getParam('transport')) !== null) {
if ($transportName !== null) { $config = CommandTransport::getConfig();
$transport = CommandTransport::create($transportName); if ($config->hasSection($transportName)) {
$transport = CommandTransport::createTransport($config->getSection($transportName));
} else { } else {
$transport = CommandTransport::first(); throw new ConfigurationError(sprintf(
mt('monitoring', 'Command transport "%s" not found.'),
$transportName
));
} }
} else {
$transport = new CommandTransport();
}
return $transport; return $transport;
} }
} }