mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-31 01:34:12 +02:00
CustomVariables: improve readability
This commit is contained in:
parent
8a3956b6a2
commit
defb8c50c2
@ -235,22 +235,29 @@ class CustomVariables implements Iterator, Countable, IcingaConfigRenderer
|
|||||||
ksort($this->vars);
|
ksort($this->vars);
|
||||||
foreach ($this->vars as $key => $var) {
|
foreach ($this->vars as $key => $var) {
|
||||||
// TODO: ctype_alnum + underscore?
|
// TODO: ctype_alnum + underscore?
|
||||||
if (preg_match('/^[a-z0-9_]+\d*$/i', $key)) {
|
$out .= $this->renderSingleVar($key, $var);
|
||||||
$out .= c::renderKeyValue(
|
|
||||||
'vars.' . c::escapeIfReserved($key),
|
|
||||||
$var->toConfigString()
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
$out .= c::renderKeyValue(
|
|
||||||
'vars[' . c::renderString($key) . ']',
|
|
||||||
$var->toConfigString()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $out;
|
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)
|
public function __get($key)
|
||||||
{
|
{
|
||||||
return $this->get($key);
|
return $this->get($key);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user