IcingaObject: prepare generic "arguments" support

This commit is contained in:
Thomas Gelf 2015-08-03 13:43:30 +02:00
parent 73ed4d398f
commit 8eb2bd7701
1 changed files with 69 additions and 2 deletions

View File

@ -22,6 +22,8 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
protected $supportsRanges = false;
protected $supportsArguments = false;
protected $supportsImports = false;
protected $supportsFields = false;
@ -38,6 +40,8 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
private $ranges;
private $arguments;
public function supportsCustomVars()
{
return $this->supportsCustomVars;
@ -53,6 +57,11 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
return $this->supportsRanges;
}
public function supportsArguments()
{
return $this->supportsArguments;
}
public function supportsImports()
{
return $this->supportsImports;
@ -112,6 +121,20 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
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()
{
$this->assertImportsSupport();
@ -315,6 +338,18 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
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()
{
if (! $this->supportsImports()) {
@ -402,15 +437,25 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
&& $this->object_type === 'apply';
}
protected function storeRelatedObjects()
{
$this
->storeCustomVars()
->storeGroups()
->storeImports()
->storeRanges()
->storeArguments();
}
public function onInsert()
{
$this->storeCustomVars()->storeGroups()->storeImports()->storeRanges();
$this->storeRelatedObjects();
DirectorActivityLog::logCreation($this, $this->connection);
}
public function onUpdate()
{
$this->storeCustomVars()->storeGroups()->storeImports()->storeRanges();
$this->storeRelatedObjects();
DirectorActivityLog::logModification($this, $this->connection);
}
@ -441,6 +486,15 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
return $this;
}
protected function storeArguments()
{
if ($this->supportsArguments()) {
$this->arguments !== null && $this->arguments()->store();
}
return $this;
}
protected function storeImports()
{
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')
{
return c::renderKeyValue(
@ -574,6 +640,7 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
$this->renderImports(),
$this->renderProperties(),
$this->renderRanges(),
$this->renderArguments(),
$this->renderGroups(),
$this->renderCustomVars(),
$this->renderSuffix()