diff --git a/library/Director/IcingaConfigHelper.php b/library/Director/IcingaConfigHelper.php new file mode 100644 index 00000000..35f2f767 --- /dev/null +++ b/library/Director/IcingaConfigHelper.php @@ -0,0 +1,35 @@ +$method($value); } else { - $out .= $this->renderKeyValue($key, $this->renderString($value)); + $out .= c::renderKeyValue($key, c::renderString($value)); } } return $out; } - protected function renderKeyValue($key, $value, $prefix = '') - { - return sprintf( - "%s %s = %s\n", - $prefix, - $key, - $value - ); - } - - protected function renderBoolean($value) - { - if ($value === 'y') { - return 'true'; - } elseif ($value === 'n') { - return 'false'; - } else { - throw new ProgrammingError('%s is not a valid boolean', $value); - } - } - protected function renderBooleanProperty($key) { - return $this->renderKeyValue($key, $this->renderBoolean($this->$key)); + return c::renderKeyValue($key, c::renderBoolean($this->$key)); } protected function renderSuffix() @@ -127,17 +107,17 @@ abstract class IcingaObject extends DbObject protected function renderCommandProperty($commandId, $propertyName = 'check_command') { - return $this->renderKeyValue( + return c::renderKeyValue( $propertyName, - $this->renderString($this->connection->getCommandName($commandId)) + c::renderString($this->connection->getCommandName($commandId)) ); } protected function renderZoneProperty($zoneId, $propertyName = 'zone') { - return $this->renderKeyValue( + return c::renderKeyValue( $propertyName, - $this->renderString($this->connection->getZoneName($zoneId)) + c::renderString($this->connection->getZoneName($zoneId)) ); } @@ -152,7 +132,7 @@ abstract class IcingaObject extends DbObject "%s %s %s {\n", $this->getObjectTypeName(), $this->getType(), - $this->renderString($this->getObjectName()) + c::renderString($this->getObjectName()) ); } @@ -167,14 +147,6 @@ abstract class IcingaObject extends DbObject )); } - protected function renderString($string) - { - $string = preg_replace('~\\\~', '\\\\', $string); - $string = preg_replace('~"~', '\\"', $string); - - return sprintf('"%s"', $string); - } - protected function getType() { if ($this->type === null) {