mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-09-21 17:07:54 +02:00
IcingaObject/ExtensibleSet: support toPlainObject
This commit is contained in:
parent
013cc1c67d
commit
c9a7c9d085
@ -59,7 +59,11 @@ class ExtensibleSet
|
|||||||
|
|
||||||
public function set($set)
|
public function set($set)
|
||||||
{
|
{
|
||||||
if (is_array($set) || is_string($set)) {
|
if (null === $set) {
|
||||||
|
$this->reset();
|
||||||
|
return $this;
|
||||||
|
|
||||||
|
} elseif (is_array($set) || is_string($set)) {
|
||||||
$this->reset();
|
$this->reset();
|
||||||
$this->override($set);
|
$this->override($set);
|
||||||
} elseif (is_object($set)) {
|
} elseif (is_object($set)) {
|
||||||
@ -79,6 +83,36 @@ class ExtensibleSet
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isEmpty()
|
||||||
|
{
|
||||||
|
return $this->ownValues === null
|
||||||
|
&& empty($this->plusValues)
|
||||||
|
&& empty($this->minusValues);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function toPlainObject()
|
||||||
|
{
|
||||||
|
if ($this->ownValues !== null) {
|
||||||
|
if (empty($this->minusValues) && empty($this->plusValues)) {
|
||||||
|
return $this->ownValues;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$plain = (object) array();
|
||||||
|
|
||||||
|
if ($this->ownValues !== null) {
|
||||||
|
$plain->override = $this->ownValues;
|
||||||
|
}
|
||||||
|
if (! empty($this->plusValues)) {
|
||||||
|
$plain->extend = $this->plusValues;
|
||||||
|
}
|
||||||
|
if (! empty($this->minusValues)) {
|
||||||
|
$plain->blacklist = $this->minusValues;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $plain;
|
||||||
|
}
|
||||||
|
|
||||||
public function hasBeenLoadedFromDb()
|
public function hasBeenLoadedFromDb()
|
||||||
{
|
{
|
||||||
return $this->fromDb !== null;
|
return $this->fromDb !== null;
|
||||||
@ -458,6 +492,7 @@ class ExtensibleSet
|
|||||||
protected function recalculate()
|
protected function recalculate()
|
||||||
{
|
{
|
||||||
$this->resolvedValues = array();
|
$this->resolvedValues = array();
|
||||||
|
|
||||||
if ($this->ownValues === null) {
|
if ($this->ownValues === null) {
|
||||||
$this->addValuesTo($this->resolvedValues, $this->inheritedValues);
|
$this->addValuesTo($this->resolvedValues, $this->inheritedValues);
|
||||||
} else {
|
} else {
|
||||||
|
@ -107,6 +107,16 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
|
|||||||
return $this->loadedRelatedSets[$property];
|
return $this->loadedRelatedSets[$property];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function relatedSets()
|
||||||
|
{
|
||||||
|
$sets = array();
|
||||||
|
foreach ($this->relatedSets as $key => $class) {
|
||||||
|
$sets[$key] = $this->getRelatedSet($key);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $sets;
|
||||||
|
}
|
||||||
|
|
||||||
public function hasRelation($property)
|
public function hasRelation($property)
|
||||||
{
|
{
|
||||||
return array_key_exists($property, $this->relations);
|
return array_key_exists($property, $this->relations);
|
||||||
@ -1278,6 +1288,27 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach ($this->relatedSets() as $property => $set) {
|
||||||
|
if ($resolved) {
|
||||||
|
$values = $set->getResolvedValues();
|
||||||
|
if (empty($values)) {
|
||||||
|
if (!$skipDefaults) {
|
||||||
|
$props[$property] = null;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$props[$property] = $values;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ($set->isEmpty()) {
|
||||||
|
if (!$skipDefaults) {
|
||||||
|
$props[$property] = null;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$props[$property] = $set->toPlainObject();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ksort($props);
|
ksort($props);
|
||||||
|
|
||||||
return (object) $props;
|
return (object) $props;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user