IcingaCommandArguments: refactor large parts
This commit is contained in:
parent
cce1e96854
commit
5e3fe5e2df
|
@ -216,6 +216,30 @@ class IcingaArguments implements Iterator, Countable, IcingaConfigRenderer
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function toPlainObject(
|
||||
$resolved = false,
|
||||
$skipDefaults = false,
|
||||
array $chosenProperties = null,
|
||||
$resolveIds = true
|
||||
) {
|
||||
$args = array();
|
||||
foreach ($this->arguments as $arg) {
|
||||
$args[$arg->argument_name] = $arg->toPlainObject($resolved, $skipDefaults);
|
||||
}
|
||||
|
||||
return $args;
|
||||
}
|
||||
|
||||
public function toUnmodifiedPlainObject()
|
||||
{
|
||||
$args = array();
|
||||
foreach ($this->storedArguments as $arg) {
|
||||
$args[] = $arg->toPlainObject();
|
||||
}
|
||||
|
||||
return $args;
|
||||
}
|
||||
|
||||
protected function cloneStored()
|
||||
{
|
||||
$this->storedArguments = array();
|
||||
|
|
|
@ -2,9 +2,10 @@
|
|||
|
||||
namespace Icinga\Module\Director\Objects;
|
||||
|
||||
use Icinga\Module\Director\Data\Db\DbObject;
|
||||
use Icinga\Module\Director\IcingaConfig\IcingaConfigHelper as c;
|
||||
|
||||
class IcingaCommandArgument extends IcingaObject
|
||||
class IcingaCommandArgument extends DbObject
|
||||
{
|
||||
protected $keyName = 'id';
|
||||
|
||||
|
@ -45,6 +46,36 @@ class IcingaCommandArgument extends IcingaObject
|
|||
// No log right now, we have to handle "sub-objects"
|
||||
}
|
||||
|
||||
public function toPlainObject(
|
||||
$resolved = false,
|
||||
$skipDefaults = false,
|
||||
array $chosenProperties = null,
|
||||
$resolveIds = true
|
||||
) {
|
||||
$keys = array(
|
||||
'argument_value',
|
||||
'argument_format',
|
||||
'key_string',
|
||||
'description',
|
||||
'skip_key',
|
||||
'set_if',
|
||||
'sort_order',
|
||||
'repeat_key',
|
||||
'set_if_format',
|
||||
);
|
||||
|
||||
$obj = (object) array();
|
||||
foreach ($keys as $key) {
|
||||
if ($skipDefaults && $this->$key === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$obj->$key = $this->$key;
|
||||
}
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
public function toConfigString()
|
||||
{
|
||||
$data = array();
|
||||
|
|
|
@ -353,15 +353,7 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
|
|||
|
||||
public function set($key, $value)
|
||||
{
|
||||
if ($key === 'arguments') {
|
||||
if (is_object($value)) {
|
||||
foreach ($value as $arg => $val) {
|
||||
$this->arguments()->set($arg, $val);
|
||||
}
|
||||
}
|
||||
return $this;
|
||||
|
||||
} elseif ($key === 'vars') {
|
||||
if ($key === 'vars') {
|
||||
$value = (array) $value;
|
||||
$unset = array();
|
||||
foreach ($this->vars() as $k => $f) {
|
||||
|
@ -380,6 +372,9 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
|
|||
//TODO: allow for deep keys
|
||||
$this->vars()->set(substr($key, 5), $value);
|
||||
return $this;
|
||||
} elseif (substr($key, 0, 10) === 'arguments.') {
|
||||
$this->arguments()->set(substr($key, 10), $value);
|
||||
return $this;
|
||||
}
|
||||
|
||||
if ($this->propertyIsBoolean($key) && $value !== null) {
|
||||
|
@ -418,6 +413,12 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
|
|||
return $this;
|
||||
}
|
||||
|
||||
protected function setArguments($value)
|
||||
{
|
||||
$this->arguments->setArguments($value);
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function getRanges()
|
||||
{
|
||||
return $this->ranges()->getValues();
|
||||
|
@ -1532,6 +1533,14 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
|
|||
}
|
||||
}
|
||||
|
||||
if ($this->supportsArguments()) {
|
||||
// TODO: resolve
|
||||
$props['arguments'] = $this->arguments()->toPlainObject(
|
||||
$resolved,
|
||||
$skipDefaults
|
||||
);
|
||||
}
|
||||
|
||||
if ($this->supportsCustomVars()) {
|
||||
if ($resolved) {
|
||||
$props['vars'] = $this->getResolvedVars();
|
||||
|
@ -1688,6 +1697,13 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
|
|||
}
|
||||
}
|
||||
|
||||
if ($this->supportsArguments()) {
|
||||
$args = $this->arguments()->toUnmodifiedPlainObject();
|
||||
if (! empty($arguments)) {
|
||||
$props['arguments'] = $arguments;
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->supportsRanges()) {
|
||||
$ranges = $this->ranges()->getOriginalValues();
|
||||
if (!empty($ranges)) {
|
||||
|
|
Loading…
Reference in New Issue