mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-31 01:34:12 +02:00
IcingaDependency: allow for arrays
This commit is contained in:
parent
05d5152e6f
commit
bb9105e370
@ -41,6 +41,12 @@ class IcingaDependency extends IcingaObject implements ExportInterface
|
|||||||
|
|
||||||
protected $supportsApplyRules = true;
|
protected $supportsApplyRules = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
protected $renderForArray = false;
|
||||||
|
|
||||||
protected $relatedSets = [
|
protected $relatedSets = [
|
||||||
'states' => 'StateFilterSet',
|
'states' => 'StateFilterSet',
|
||||||
];
|
];
|
||||||
@ -114,6 +120,11 @@ class IcingaDependency extends IcingaObject implements ExportInterface
|
|||||||
return $object;
|
return $object;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function parentHostIsVar()
|
||||||
|
{
|
||||||
|
return $this->get('parent_host_var') !== null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
* @throws ConfigurationError
|
* @throws ConfigurationError
|
||||||
@ -128,18 +139,78 @@ class IcingaDependency extends IcingaObject implements ExportInterface
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return sprintf(
|
if ($this->renderForArray) {
|
||||||
"%s %s %s to %s {\n",
|
return $this->renderArrayObjectHeader($to);
|
||||||
$this->getObjectTypeName(),
|
} else {
|
||||||
$this->getType(),
|
return $this->renderSingleObjectHeader($to);
|
||||||
c::renderString($this->getObjectName()),
|
}
|
||||||
ucfirst($to)
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
return parent::renderObjectHeader();
|
return parent::renderObjectHeader();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function renderSingleObjectHeader($to)
|
||||||
|
{
|
||||||
|
return sprintf(
|
||||||
|
"%s %s %s to %s {\n",
|
||||||
|
$this->getObjectTypeName(),
|
||||||
|
$this->getType(),
|
||||||
|
c::renderString($this->getObjectName()),
|
||||||
|
ucfirst($to)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function renderArrayObjectHeader($to)
|
||||||
|
{
|
||||||
|
return sprintf(
|
||||||
|
"%s %s %s for (host_parent_name in %s) to %s {\n",
|
||||||
|
$this->getObjectTypeName(),
|
||||||
|
$this->getType(),
|
||||||
|
c::renderString($this->getObjectName()),
|
||||||
|
$this->get('parent_host_var'),
|
||||||
|
ucfirst($to)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function renderSuffix()
|
||||||
|
{
|
||||||
|
if ($this->parentHostIsVar() && ! $this->renderForArray) {
|
||||||
|
return parent::renderSuffix() . $this->renderCloneForArray();
|
||||||
|
} else {
|
||||||
|
return parent::renderSuffix();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function renderCloneForArray()
|
||||||
|
{
|
||||||
|
$clone = clone($this);
|
||||||
|
$clone->renderForArray = true;
|
||||||
|
|
||||||
|
return $clone->toConfigString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @codingStandardsIgnoreStart
|
||||||
|
*/
|
||||||
|
public function renderAssign_Filter()
|
||||||
|
{
|
||||||
|
if ($this->parentHostIsVar()) {
|
||||||
|
$varName = $this->get('parent_host_var');
|
||||||
|
if ($this->renderForArray) {
|
||||||
|
$suffix = sprintf(' && typeof(%s) == Array', $varName);
|
||||||
|
} else {
|
||||||
|
$suffix = sprintf(' && typeof(%s) == String', $varName);
|
||||||
|
}
|
||||||
|
|
||||||
|
return preg_replace('/\n$/m', $suffix, parent::renderAssign_Filter() . "\n");
|
||||||
|
} else {
|
||||||
|
return parent::renderAssign_Filter();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected function setKey($key)
|
protected function setKey($key)
|
||||||
{
|
{
|
||||||
// TODO: Check if this method can be removed
|
// TODO: Check if this method can be removed
|
||||||
@ -303,7 +374,6 @@ class IcingaDependency extends IcingaObject implements ExportInterface
|
|||||||
public function renderParent_host_id()
|
public function renderParent_host_id()
|
||||||
{
|
{
|
||||||
// @codingStandardsIgnoreEnd
|
// @codingStandardsIgnoreEnd
|
||||||
|
|
||||||
return $this->renderRelationProperty(
|
return $this->renderRelationProperty(
|
||||||
'parent_host',
|
'parent_host',
|
||||||
$this->get('parent_host_id'),
|
$this->get('parent_host_id'),
|
||||||
@ -319,6 +389,14 @@ class IcingaDependency extends IcingaObject implements ExportInterface
|
|||||||
*/
|
*/
|
||||||
public function renderParent_host_var()
|
public function renderParent_host_var()
|
||||||
{
|
{
|
||||||
|
// @codingStandardsIgnoreEnd
|
||||||
|
if ($this->renderForArray) {
|
||||||
|
return c::renderKeyValue(
|
||||||
|
'parent_host_name',
|
||||||
|
'host_parent_name'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// @codingStandardsIgnoreEnd
|
// @codingStandardsIgnoreEnd
|
||||||
return c::renderKeyValue(
|
return c::renderKeyValue(
|
||||||
'parent_host_name',
|
'parent_host_name',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user