diff --git a/library/Director/CustomVariable/CustomVariables.php b/library/Director/CustomVariable/CustomVariables.php index a7b4c0cc..f5de9b72 100644 --- a/library/Director/CustomVariable/CustomVariables.php +++ b/library/Director/CustomVariable/CustomVariables.php @@ -235,22 +235,29 @@ class CustomVariables implements Iterator, Countable, IcingaConfigRenderer ksort($this->vars); foreach ($this->vars as $key => $var) { // TODO: ctype_alnum + underscore? - if (preg_match('/^[a-z0-9_]+\d*$/i', $key)) { - $out .= c::renderKeyValue( - 'vars.' . c::escapeIfReserved($key), - $var->toConfigString() - ); - } else { - $out .= c::renderKeyValue( - 'vars[' . c::renderString($key) . ']', - $var->toConfigString() - ); - } + $out .= $this->renderSingleVar($key, $var); } return $out; } + protected function renderSingleVar($key, $var) + { + return c::renderKeyValue( + $this->renderKeyName($key), + $var->toConfigString() + ); + } + + protected function renderKeyName($key) + { + if (preg_match('/^[a-z0-9_]+\d*$/i', $key)) { + return 'vars.' . c::escapeIfReserved($key); + } else { + return 'vars[' . c::renderString($key) . ']'; + } + } + public function __get($key) { return $this->get($key);