From 8eb2bd7701b6390a852c746376d89da9cc768c69 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Mon, 3 Aug 2015 13:43:30 +0200 Subject: [PATCH] IcingaObject: prepare generic "arguments" support --- library/Director/Objects/IcingaObject.php | 71 ++++++++++++++++++++++- 1 file changed, 69 insertions(+), 2 deletions(-) diff --git a/library/Director/Objects/IcingaObject.php b/library/Director/Objects/IcingaObject.php index 8b761114..a30d7954 100644 --- a/library/Director/Objects/IcingaObject.php +++ b/library/Director/Objects/IcingaObject.php @@ -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()