IcingaObject: prepare generic "arguments" support
This commit is contained in:
parent
73ed4d398f
commit
8eb2bd7701
|
@ -22,6 +22,8 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
|
||||||
|
|
||||||
protected $supportsRanges = false;
|
protected $supportsRanges = false;
|
||||||
|
|
||||||
|
protected $supportsArguments = false;
|
||||||
|
|
||||||
protected $supportsImports = false;
|
protected $supportsImports = false;
|
||||||
|
|
||||||
protected $supportsFields = false;
|
protected $supportsFields = false;
|
||||||
|
@ -38,6 +40,8 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
|
||||||
|
|
||||||
private $ranges;
|
private $ranges;
|
||||||
|
|
||||||
|
private $arguments;
|
||||||
|
|
||||||
public function supportsCustomVars()
|
public function supportsCustomVars()
|
||||||
{
|
{
|
||||||
return $this->supportsCustomVars;
|
return $this->supportsCustomVars;
|
||||||
|
@ -53,6 +57,11 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
|
||||||
return $this->supportsRanges;
|
return $this->supportsRanges;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function supportsArguments()
|
||||||
|
{
|
||||||
|
return $this->supportsArguments;
|
||||||
|
}
|
||||||
|
|
||||||
public function supportsImports()
|
public function supportsImports()
|
||||||
{
|
{
|
||||||
return $this->supportsImports;
|
return $this->supportsImports;
|
||||||
|
@ -112,6 +121,20 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
|
||||||
return $this->ranges;
|
return $this->ranges;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function arguments()
|
||||||
|
{
|
||||||
|
$this->assertArgumentsSupport();
|
||||||
|
if ($this->arguments === null) {
|
||||||
|
if ($this->hasBeenLoadedFromDb()) {
|
||||||
|
$this->arguments = IcingaArguments::loadForStoredObject($this);
|
||||||
|
} else {
|
||||||
|
$this->arguments = new IcingaArguments($this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->arguments;
|
||||||
|
}
|
||||||
|
|
||||||
public function imports()
|
public function imports()
|
||||||
{
|
{
|
||||||
$this->assertImportsSupport();
|
$this->assertImportsSupport();
|
||||||
|
@ -315,6 +338,18 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function assertArgumentsSupport()
|
||||||
|
{
|
||||||
|
if (! $this->supportsArguments()) {
|
||||||
|
throw new ProgrammingError(
|
||||||
|
'Objects of type "%s" have no arguments',
|
||||||
|
$this->getType()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
protected function assertImportsSupport()
|
protected function assertImportsSupport()
|
||||||
{
|
{
|
||||||
if (! $this->supportsImports()) {
|
if (! $this->supportsImports()) {
|
||||||
|
@ -402,15 +437,25 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
|
||||||
&& $this->object_type === 'apply';
|
&& $this->object_type === 'apply';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function storeRelatedObjects()
|
||||||
|
{
|
||||||
|
$this
|
||||||
|
->storeCustomVars()
|
||||||
|
->storeGroups()
|
||||||
|
->storeImports()
|
||||||
|
->storeRanges()
|
||||||
|
->storeArguments();
|
||||||
|
}
|
||||||
|
|
||||||
public function onInsert()
|
public function onInsert()
|
||||||
{
|
{
|
||||||
$this->storeCustomVars()->storeGroups()->storeImports()->storeRanges();
|
$this->storeRelatedObjects();
|
||||||
DirectorActivityLog::logCreation($this, $this->connection);
|
DirectorActivityLog::logCreation($this, $this->connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onUpdate()
|
public function onUpdate()
|
||||||
{
|
{
|
||||||
$this->storeCustomVars()->storeGroups()->storeImports()->storeRanges();
|
$this->storeRelatedObjects();
|
||||||
DirectorActivityLog::logModification($this, $this->connection);
|
DirectorActivityLog::logModification($this, $this->connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -441,6 +486,15 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function storeArguments()
|
||||||
|
{
|
||||||
|
if ($this->supportsArguments()) {
|
||||||
|
$this->arguments !== null && $this->arguments()->store();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
protected function storeImports()
|
protected function storeImports()
|
||||||
{
|
{
|
||||||
if ($this->supportsImports()) {
|
if ($this->supportsImports()) {
|
||||||
|
@ -536,6 +590,18 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function renderArguments()
|
||||||
|
{
|
||||||
|
if ($this->supportsArguments()) {
|
||||||
|
return $this->arguments()->toConfigString();
|
||||||
|
} else {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}
|
||||||
protected function renderCommandProperty($commandId, $propertyName = 'check_command')
|
protected function renderCommandProperty($commandId, $propertyName = 'check_command')
|
||||||
{
|
{
|
||||||
return c::renderKeyValue(
|
return c::renderKeyValue(
|
||||||
|
@ -574,6 +640,7 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
|
||||||
$this->renderImports(),
|
$this->renderImports(),
|
||||||
$this->renderProperties(),
|
$this->renderProperties(),
|
||||||
$this->renderRanges(),
|
$this->renderRanges(),
|
||||||
|
$this->renderArguments(),
|
||||||
$this->renderGroups(),
|
$this->renderGroups(),
|
||||||
$this->renderCustomVars(),
|
$this->renderCustomVars(),
|
||||||
$this->renderSuffix()
|
$this->renderSuffix()
|
||||||
|
|
Loading…
Reference in New Issue