IcingaConfig: improve prefix/intendation handling

This commit is contained in:
Thomas Gelf 2015-06-11 23:02:43 +02:00
parent 055895a553
commit f354d3c034
4 changed files with 16 additions and 14 deletions

View File

@ -65,9 +65,8 @@ class CustomVariables
foreach ($this->vars as $key => $var) {
$out .= c::renderKeyValue(
c::escapeIfReserved($key),
$var->toConfigString(),
' vars.'
'vars.' . c::escapeIfReserved($key),
$var->toConfigString()
);
}

View File

@ -35,14 +35,19 @@ class IcingaConfigHelper
'in',
);
public static function renderKeyValue($key, $value, $prefix = '')
public static function renderKeyValue($key, $value, $prefix = ' ')
{
return sprintf(
"%s%s = %s\n",
$prefix,
$string = sprintf(
"%s = %s",
$key,
$value
);
if ($prefix && strpos($string, "\n") !== false) {
return $prefix . implode("\n" . $prefix, explode("\n", $string)) . "\n";
}
return $prefix . $string . "\n";
}
public static function renderBoolean($value)

View File

@ -21,6 +21,6 @@ class IcingaCommand extends IcingaObject
protected function renderMethods_execute()
{
// Execute is a reserved word in SQL, column name was prefixed
return c::renderKeyValue('execute', $this->methods_execute, ' ');
return c::renderKeyValue('execute', $this->methods_execute);
}
}

View File

@ -98,7 +98,7 @@ abstract class IcingaObject extends DbObject
if (method_exists($this, $method)) {
$out .= $this->$method($value);
} else {
$out .= c::renderKeyValue($key, c::renderString($value), ' ');
$out .= c::renderKeyValue($key, c::renderString($value));
}
}
@ -111,7 +111,7 @@ abstract class IcingaObject extends DbObject
protected function renderBooleanProperty($key)
{
return c::renderKeyValue($key, c::renderBoolean($this->$key), ' ');
return c::renderKeyValue($key, c::renderBoolean($this->$key));
}
protected function renderSuffix()
@ -135,8 +135,7 @@ abstract class IcingaObject extends DbObject
{
return c::renderKeyValue(
$propertyName,
c::renderString($this->connection->getCommandName($commandId)),
' '
c::renderString($this->connection->getCommandName($commandId))
);
}
@ -144,8 +143,7 @@ abstract class IcingaObject extends DbObject
{
return c::renderKeyValue(
$propertyName,
c::renderString($this->connection->getZoneName($zoneId)),
' '
c::renderString($this->connection->getZoneName($zoneId))
);
}