diff --git a/library/Director/CustomVariable/CustomVariable.php b/library/Director/CustomVariable/CustomVariable.php index bfa6e617..50b47f55 100644 --- a/library/Director/CustomVariable/CustomVariable.php +++ b/library/Director/CustomVariable/CustomVariable.php @@ -39,14 +39,24 @@ abstract class CustomVariable return $this->type; } + public function getKey() + { + return $this->key; + } + + public function getValue() + { + return $this->value; + } + public function setValue($value) { if ($value instanceof CustomVariable) { if (! $this->equals($value)) { - $this->reallySet($value); + $this->reallySetValue($value); } } elseif ($value !== $this->value) { - $this->reallySet($value); + $this->reallySetValue($value); } return $this; @@ -87,7 +97,7 @@ abstract class CustomVariable } elseif (is_array($value)) { - foreach (array_keys($value) as & $key) { + foreach (array_keys($value) as $key) { if (! is_int($key) || ctype_digit($key)) { return new CustomVariableDictionary($key, $value); } diff --git a/library/Director/CustomVariable/CustomVariables.php b/library/Director/CustomVariable/CustomVariables.php index 7ca9a155..e15f91bd 100644 --- a/library/Director/CustomVariable/CustomVariables.php +++ b/library/Director/CustomVariable/CustomVariables.php @@ -22,12 +22,11 @@ class CustomVariables { $key = (string) $key; - // TODO: add support for null values - if ($value === null) { - unset($this->$key); + if (! $value instanceof CustomVariable) { + $value = CustomVariable::create($key, $value); } - if ($value === $this->get($key)) { + if (isset($this->$key) && $value->equals($this->get($key))) { return $this; } @@ -37,6 +36,15 @@ class CustomVariables return $this; } + public function get($key) + { + if (array_key_exists($key, $this->vars)) { + return $this->vars[$key]; + } + + return null; + } + public function hasBeenModified() { return $this->modified; @@ -54,7 +62,7 @@ class CustomVariables $out = ''; foreach ($this->vars as $key => $var) { - $out .= $var->toConfigString() + $out .= $var->toConfigString(); } return $out; @@ -85,7 +93,7 @@ class CustomVariables */ public function __isset($key) { - return array_key_exists($key, $this->properties); + return array_key_exists($key, $this->vars); } /** diff --git a/library/Director/Objects/IcingaObject.php b/library/Director/Objects/IcingaObject.php index 6d3c1154..2eee1fe9 100644 --- a/library/Director/Objects/IcingaObject.php +++ b/library/Director/Objects/IcingaObject.php @@ -18,6 +18,8 @@ abstract class IcingaObject extends DbObject private $type; + private $vars; + public function supportsCustomVars() { return $this->supportsCustomVars; @@ -100,6 +102,10 @@ abstract class IcingaObject extends DbObject } } + if ($this->supportsCustomVars()) { + $out .= $this->vars()->toConfigString(); + } + return $out; }