CustomVariables: implement and use basic rendering

This commit is contained in:
Thomas Gelf 2015-06-11 19:46:36 +02:00
parent 93ead1f68e
commit b2f66b3995
3 changed files with 33 additions and 9 deletions

View File

@ -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);
}

View File

@ -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);
}
/**

View File

@ -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;
}