IcingaCommand: add mungeCommand

Supports arrays and optional PluginDir resolution
This commit is contained in:
Thomas Gelf 2015-12-02 03:20:55 +01:00
parent 502e139516
commit e29da23f99
1 changed files with 26 additions and 0 deletions

View File

@ -28,12 +28,33 @@ class IcingaCommand extends IcingaObject
protected $supportsArguments = true;
protected static $pluginDir;
protected function renderMethods_execute()
{
// Execute is a reserved word in SQL, column name was prefixed
return c::renderKeyValue('execute', $this->methods_execute);
}
public function mungeCommand($value)
{
if (is_array($value)) {
$value = implode(' ', $value);
} elseif (is_object($value)) {
// { type => Function } -> really??
return null;
return $value;
}
if (self::$pluginDir !== null) {
if (($pos = strpos($value, self::$pluginDir)) === 0) {
$value = substr($value, strlen(self::$pluginDir) + 1);
}
}
return $value;
}
protected function renderCommand()
{
$command = $this->command;
@ -59,4 +80,9 @@ class IcingaCommand extends IcingaObject
}
return c::renderKeyValue('timeout', $value);
}
public static function setPluginDir($pluginDir)
{
self::$pluginDir = $pluginDir;
}
}