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) { foreach ($this->vars as $key => $var) {
$out .= c::renderKeyValue( $out .= c::renderKeyValue(
c::escapeIfReserved($key), 'vars.' . c::escapeIfReserved($key),
$var->toConfigString(), $var->toConfigString()
' vars.'
); );
} }

View File

@ -35,14 +35,19 @@ class IcingaConfigHelper
'in', 'in',
); );
public static function renderKeyValue($key, $value, $prefix = '') public static function renderKeyValue($key, $value, $prefix = ' ')
{ {
return sprintf( $string = sprintf(
"%s%s = %s\n", "%s = %s",
$prefix,
$key, $key,
$value $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) public static function renderBoolean($value)

View File

@ -21,6 +21,6 @@ class IcingaCommand extends IcingaObject
protected function renderMethods_execute() protected function renderMethods_execute()
{ {
// Execute is a reserved word in SQL, column name was prefixed // 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)) { if (method_exists($this, $method)) {
$out .= $this->$method($value); $out .= $this->$method($value);
} else { } 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) protected function renderBooleanProperty($key)
{ {
return c::renderKeyValue($key, c::renderBoolean($this->$key), ' '); return c::renderKeyValue($key, c::renderBoolean($this->$key));
} }
protected function renderSuffix() protected function renderSuffix()
@ -135,8 +135,7 @@ abstract class IcingaObject extends DbObject
{ {
return c::renderKeyValue( return c::renderKeyValue(
$propertyName, $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( return c::renderKeyValue(
$propertyName, $propertyName,
c::renderString($this->connection->getZoneName($zoneId)), c::renderString($this->connection->getZoneName($zoneId))
' '
); );
} }