2015-06-01 16:28:40 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Icinga\Module\Director\Objects;
|
|
|
|
|
2016-03-21 10:12:49 +01:00
|
|
|
use Icinga\Module\Director\Objects\IcingaObject;
|
2015-10-16 18:42:38 +02:00
|
|
|
use Icinga\Module\Director\IcingaConfig\IcingaConfigHelper as c;
|
|
|
|
|
2016-03-21 10:12:49 +01:00
|
|
|
class IcingaCommandArgument extends IcingaObject
|
2015-06-01 16:28:40 +02:00
|
|
|
{
|
2015-07-02 14:31:35 +02:00
|
|
|
protected $keyName = 'id';
|
|
|
|
|
2015-06-01 16:28:40 +02:00
|
|
|
protected $table = 'icinga_command_argument';
|
|
|
|
|
2015-12-02 02:51:17 +01:00
|
|
|
protected $booleans = array(
|
|
|
|
'skip_key' => 'skip_key',
|
2016-03-21 10:12:49 +01:00
|
|
|
'repeat_key' => 'repeat_key',
|
|
|
|
'required' => 'required'
|
2015-12-02 02:51:17 +01:00
|
|
|
);
|
|
|
|
|
2015-06-01 16:28:40 +02:00
|
|
|
protected $defaultProperties = array(
|
2015-08-03 13:53:58 +02:00
|
|
|
'id' => null,
|
|
|
|
'command_id' => null,
|
|
|
|
'argument_name' => null,
|
|
|
|
'argument_value' => null,
|
|
|
|
'argument_format' => null,
|
|
|
|
'key_string' => null,
|
|
|
|
'description' => null,
|
|
|
|
'skip_key' => null,
|
|
|
|
'set_if' => null,
|
|
|
|
'sort_order' => null,
|
|
|
|
'repeat_key' => null,
|
|
|
|
'set_if_format' => null,
|
2016-03-21 10:12:49 +01:00
|
|
|
'required' => null,
|
2015-06-01 16:28:40 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
public function onInsert()
|
|
|
|
{
|
|
|
|
// No log right now, we have to handle "sub-objects"
|
|
|
|
}
|
|
|
|
|
|
|
|
public function onUpdate()
|
|
|
|
{
|
|
|
|
// No log right now, we have to handle "sub-objects"
|
|
|
|
}
|
|
|
|
|
|
|
|
public function onDelete()
|
|
|
|
{
|
|
|
|
// No log right now, we have to handle "sub-objects"
|
|
|
|
}
|
2015-10-16 18:42:38 +02:00
|
|
|
|
2016-03-18 13:46:06 +01:00
|
|
|
public function toPlainObject(
|
|
|
|
$resolved = false,
|
|
|
|
$skipDefaults = false,
|
|
|
|
array $chosenProperties = null,
|
|
|
|
$resolveIds = true
|
|
|
|
) {
|
2016-03-21 10:12:49 +01:00
|
|
|
// TODO: skipDefaults?
|
|
|
|
|
|
|
|
$data = array();
|
|
|
|
if ($this->argument_value) {
|
|
|
|
switch ($this->argument_format) {
|
|
|
|
case 'string':
|
|
|
|
case 'json':
|
|
|
|
$data['value'] = $this->argument_value;
|
|
|
|
break;
|
|
|
|
case 'expression':
|
|
|
|
$data['value'] = (object) array(
|
|
|
|
'type' => 'Function',
|
|
|
|
// TODO: Not for dummy comment
|
|
|
|
'body' => $this->argument_value
|
|
|
|
);
|
|
|
|
break;
|
2016-03-18 13:46:06 +01:00
|
|
|
}
|
2016-03-21 10:12:49 +01:00
|
|
|
}
|
2016-03-18 13:46:06 +01:00
|
|
|
|
2016-03-21 10:12:49 +01:00
|
|
|
if ($this->sort_order !== null) {
|
|
|
|
$data['order'] = $this->sort_order;
|
2016-03-18 13:46:06 +01:00
|
|
|
}
|
|
|
|
|
2016-03-21 10:12:49 +01:00
|
|
|
if ($this->set_if) {
|
|
|
|
$data['set_if'] = $this->set_if;
|
|
|
|
}
|
|
|
|
|
2016-03-28 23:48:19 +02:00
|
|
|
if ($this->required !== null) {
|
2016-03-21 10:12:49 +01:00
|
|
|
$data['required'] = $this->required === 'y';
|
|
|
|
}
|
|
|
|
|
2016-03-28 23:48:19 +02:00
|
|
|
if ($this->repeat_key !== null) {
|
2016-03-21 10:12:49 +01:00
|
|
|
$data['repeat_key'] = $this->repeat_key === 'y';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->description) {
|
|
|
|
$data['description'] = $this->description;
|
|
|
|
}
|
|
|
|
|
2016-03-28 23:50:15 +02:00
|
|
|
if ($resolveIds) {
|
|
|
|
if (array_keys($data) === array('value')) {
|
|
|
|
return $data['value'];
|
|
|
|
} else {
|
|
|
|
return (object) $data;
|
|
|
|
}
|
2016-03-21 10:12:49 +01:00
|
|
|
} else {
|
2016-03-28 23:50:15 +02:00
|
|
|
unset($data['value']);
|
|
|
|
unset($data['order']);
|
|
|
|
$data['sort_order'] = $this->sort_order;
|
|
|
|
$data['command_id'] = $this->command_id;
|
|
|
|
$data['argument_name'] = $this->argument_name;
|
|
|
|
$data['argument_value'] = $this->argument_value;
|
|
|
|
$data['argument_format'] = $this->argument_format;
|
|
|
|
return (object) $data;
|
2016-03-21 10:12:49 +01:00
|
|
|
}
|
2016-03-18 13:46:06 +01:00
|
|
|
}
|
|
|
|
|
2015-10-16 18:42:38 +02:00
|
|
|
public function toConfigString()
|
|
|
|
{
|
|
|
|
$data = array();
|
|
|
|
if ($this->argument_value) {
|
|
|
|
switch ($this->argument_format) {
|
|
|
|
case 'string':
|
|
|
|
$data['value'] = c::renderString($this->argument_value);
|
|
|
|
break;
|
2015-12-02 02:51:17 +01:00
|
|
|
case 'json':
|
|
|
|
if (is_object($this->argument_value)) {
|
|
|
|
$data['value'] = c::renderDictionary($this->argument_value);
|
|
|
|
} elseif (is_array($this->argument_value)) {
|
|
|
|
$data['value'] = c::renderArray($this->argument_value);
|
2015-12-18 16:11:36 +01:00
|
|
|
} elseif (is_null($this->argument_value)) {
|
|
|
|
// TODO: recheck all this. I bet we never reach this:
|
|
|
|
$data['value'] = 'null';
|
|
|
|
} elseif (is_bool($this->argument_value)) {
|
|
|
|
$data['value'] = c::renderBoolean($this->argument_value);
|
2015-12-02 02:51:17 +01:00
|
|
|
} else {
|
2015-12-18 16:11:36 +01:00
|
|
|
$data['value'] = $this->argument_value;
|
2015-12-02 02:51:17 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'expression':
|
|
|
|
$data['value'] = c::renderExpression($this->argument_value);
|
|
|
|
break;
|
2015-10-16 18:42:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-21 10:12:49 +01:00
|
|
|
if ($this->sort_order !== null) {
|
2015-10-16 18:42:38 +02:00
|
|
|
$data['order'] = $this->sort_order;
|
|
|
|
}
|
|
|
|
|
2015-12-02 02:51:17 +01:00
|
|
|
if ($this->set_if) {
|
|
|
|
$data['set_if'] = c::renderString($this->set_if);
|
|
|
|
}
|
|
|
|
|
2016-03-21 10:12:49 +01:00
|
|
|
if ($this->required) {
|
|
|
|
$data['required'] = c::renderBoolean($this->required);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->repeat_key) {
|
|
|
|
$data['repeat_key'] = c::renderBoolean($this->repeat_key);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if ((int) $this->sort_order !== 0) {
|
2015-12-02 02:51:17 +01:00
|
|
|
$data['order'] = $this->sort_order;
|
|
|
|
}
|
|
|
|
|
2016-03-21 10:12:49 +01:00
|
|
|
*/
|
2015-12-02 02:51:17 +01:00
|
|
|
if ($this->description) {
|
|
|
|
$data['description'] = c::renderString($this->description);
|
|
|
|
}
|
|
|
|
|
2015-12-18 16:02:48 +01:00
|
|
|
if (array_keys($data) === array('value')) {
|
|
|
|
return $data['value'];
|
|
|
|
} else {
|
|
|
|
return c::renderDictionary($data);
|
|
|
|
}
|
2015-10-16 18:42:38 +02:00
|
|
|
}
|
2015-06-01 16:28:40 +02:00
|
|
|
}
|