CustomVariableDictionary: rudimentary rendering

This commit is contained in:
Thomas Gelf 2015-06-15 14:51:06 +02:00
parent 212a36a858
commit fbc56df500
2 changed files with 33 additions and 1 deletions

View File

@ -2,6 +2,7 @@
namespace Icinga\Module\Director\CustomVariable;
use Icinga\Module\Director\IcingaConfig\IcingaConfigHelper as c;
use Countable;
class CustomVariableDictionary extends CustomVariable implements Countable
@ -27,6 +28,25 @@ class CustomVariableDictionary extends CustomVariable implements Countable
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()
{
$keys = array_keys($this->value);
@ -53,6 +73,6 @@ class CustomVariableDictionary extends CustomVariable implements Countable
public function toConfigString()
{
// TODO: Implement toConfigString() method.
return c::renderDictionary($this->value);
}
}

View File

@ -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)
{
return in_array($string, self::$reservedWords);