IcingaObjectImports: fix null handling

This commit is contained in:
Thomas Gelf 2016-05-20 08:12:46 +02:00
parent e1c05e5a3a
commit 64fbdcfeee
2 changed files with 11 additions and 2 deletions

View File

@ -587,7 +587,7 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
public function setImports($imports)
{
if (! is_array($imports)) {
if (! is_array($imports) && $imports !== null) {
$imports = array($imports);
}

View File

@ -81,9 +81,18 @@ class IcingaObjectImports implements Iterator, Countable, IcingaConfigRenderer
public function set($import)
{
if ($import === null) {
if (empty($this->imports)) {
return $this;
} else {
return $this->clear();
}
}
if (! is_array($import)) {
$import = array($import);
}
$existing = array_keys($this->imports);
$new = array();
$class = $this->getImportClass();
@ -105,7 +114,6 @@ class IcingaObjectImports implements Iterator, Countable, IcingaConfigRenderer
}
$this->imports = array();
$this->modified = true;
return $this->add($import);
}
@ -301,6 +309,7 @@ class IcingaObjectImports implements Iterator, Countable, IcingaConfigRenderer
foreach ($this->objects as $k => $v) {
$this->storedImports[$k] = clone($v);
}
$this->modified = false;
}
protected function getImportClass()