IcingaObject: allow to access custom vars

This commit is contained in:
Thomas Gelf 2015-06-11 19:18:47 +02:00
parent 8184605c32
commit 57d443157f
1 changed files with 23 additions and 0 deletions

View File

@ -2,6 +2,7 @@
namespace Icinga\Module\Director\Objects;
use Icinga\Module\Director\CustomVariable\CustomVariables;
use Icinga\Module\Director\Data\Db\DbObject;
use Icinga\Module\Director\IcingaConfigHelper as c;
use Icinga\Exception\ProgrammingError;
@ -22,6 +23,28 @@ abstract class IcingaObject extends DbObject
return $this->supportsCustomVars;
}
protected function assertCustomVarsSupport()
{
if (! $this->supportsCustomVars()) {
throw new ProgrammingError(
'Objects of type "%s" have no custom vars',
$this->getType()
);
}
return $this;
}
public function vars()
{
$this->assertCustomVarsSupport();
if ($this->vars === null) {
$this->vars = new CustomVariables();
}
return $this->vars;
}
public function isTemplate()
{
return $this->hasProperty('object_type')