CustomVariable: new helper methods
This commit is contained in:
parent
ac5bfd32f3
commit
8267e377ea
|
@ -17,6 +17,10 @@ abstract class CustomVariable implements IcingaConfigRenderer
|
||||||
|
|
||||||
protected $modified = false;
|
protected $modified = false;
|
||||||
|
|
||||||
|
protected $loadedFromDb = false;
|
||||||
|
|
||||||
|
protected $deleted = false;
|
||||||
|
|
||||||
protected function __construct($key, $value = null)
|
protected function __construct($key, $value = null)
|
||||||
{
|
{
|
||||||
$this->key = $key;
|
$this->key = $key;
|
||||||
|
@ -40,6 +44,25 @@ abstract class CustomVariable implements IcingaConfigRenderer
|
||||||
return $this->type;
|
return $this->type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: implement delete()
|
||||||
|
|
||||||
|
public function hasBeenDeleted()
|
||||||
|
{
|
||||||
|
return $this->deleted;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: abstract
|
||||||
|
public function getDbValue()
|
||||||
|
{
|
||||||
|
return $this->getValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: abstract
|
||||||
|
public function getDbFormat()
|
||||||
|
{
|
||||||
|
return 'string';
|
||||||
|
}
|
||||||
|
|
||||||
public function getKey()
|
public function getKey()
|
||||||
{
|
{
|
||||||
return $this->key;
|
return $this->key;
|
||||||
|
@ -47,6 +70,11 @@ abstract class CustomVariable implements IcingaConfigRenderer
|
||||||
|
|
||||||
abstract public function setValue($value);
|
abstract public function setValue($value);
|
||||||
|
|
||||||
|
public function isNew()
|
||||||
|
{
|
||||||
|
return ! $this->loadedFromDb;
|
||||||
|
}
|
||||||
|
|
||||||
public function hasBeenModified()
|
public function hasBeenModified()
|
||||||
{
|
{
|
||||||
return $this->modified;
|
return $this->modified;
|
||||||
|
@ -114,9 +142,11 @@ abstract class CustomVariable implements IcingaConfigRenderer
|
||||||
{
|
{
|
||||||
switch($row->format) {
|
switch($row->format) {
|
||||||
case 'string':
|
case 'string':
|
||||||
return new CustomVariableString($row->varname, $row->varvalue);
|
$var = new CustomVariableString($row->varname, $row->varvalue);
|
||||||
|
break;
|
||||||
case 'json':
|
case 'json':
|
||||||
return self::create($row->varname, json_decode($row->varvalue));
|
$var = self::create($row->varname, json_decode($row->varvalue));
|
||||||
|
break;
|
||||||
case 'expression':
|
case 'expression':
|
||||||
throw new ProgrammingError(
|
throw new ProgrammingError(
|
||||||
'Icinga code expressions are not yet supported'
|
'Icinga code expressions are not yet supported'
|
||||||
|
@ -127,6 +157,9 @@ abstract class CustomVariable implements IcingaConfigRenderer
|
||||||
$row->format
|
$row->format
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$var->loadedFromDb = true;
|
||||||
|
return $var;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __toString()
|
public function __toString()
|
||||||
|
|
Loading…
Reference in New Issue