CustomVariableDictionary: rudimentary rendering
This commit is contained in:
parent
212a36a858
commit
fbc56df500
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace Icinga\Module\Director\CustomVariable;
|
namespace Icinga\Module\Director\CustomVariable;
|
||||||
|
|
||||||
|
use Icinga\Module\Director\IcingaConfig\IcingaConfigHelper as c;
|
||||||
use Countable;
|
use Countable;
|
||||||
|
|
||||||
class CustomVariableDictionary extends CustomVariable implements Countable
|
class CustomVariableDictionary extends CustomVariable implements Countable
|
||||||
|
@ -27,6 +28,25 @@ class CustomVariableDictionary extends CustomVariable implements Countable
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setValue($value)
|
||||||
|
{
|
||||||
|
$new = array();
|
||||||
|
|
||||||
|
foreach ($value as $key => $val) {
|
||||||
|
$new[$key] = self::wantCustomVariable($key, $val);
|
||||||
|
}
|
||||||
|
|
||||||
|
// WTF?
|
||||||
|
if ($this->value === $new) {
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->value = $new;
|
||||||
|
$this->setModified();
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function listKeys()
|
public function listKeys()
|
||||||
{
|
{
|
||||||
$keys = array_keys($this->value);
|
$keys = array_keys($this->value);
|
||||||
|
@ -53,6 +73,6 @@ class CustomVariableDictionary extends CustomVariable implements Countable
|
||||||
|
|
||||||
public function toConfigString()
|
public function toConfigString()
|
||||||
{
|
{
|
||||||
// TODO: Implement toConfigString() method.
|
return c::renderDictionary($this->value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,6 +106,18 @@ class IcingaConfigHelper
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function renderDictionary($dictionary)
|
||||||
|
{
|
||||||
|
$vals = array();
|
||||||
|
foreach ($dictionary as $key => $value) {
|
||||||
|
$vals[] = rtrim(self::renderKeyValue(self::renderString($key), $value));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prefix for toConfigString?
|
||||||
|
return "{\n" . implode("\n", $vals) . "\n}";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public static function isReserved($string)
|
public static function isReserved($string)
|
||||||
{
|
{
|
||||||
return in_array($string, self::$reservedWords);
|
return in_array($string, self::$reservedWords);
|
||||||
|
|
Loading…
Reference in New Issue