IcingaObject: add userspace filters

This commit is contained in:
Thomas Gelf 2015-12-02 04:04:19 +01:00
parent d8a5e9a636
commit dabc6de1da
1 changed files with 31 additions and 0 deletions

View File

@ -7,6 +7,7 @@ use Icinga\Module\Director\Data\Db\DbObject;
use Icinga\Module\Director\Db;
use Icinga\Module\Director\IcingaConfig\IcingaConfigRenderer;
use Icinga\Module\Director\IcingaConfig\IcingaConfigHelper as c;
use Icinga\Data\Filter\Filter;
use Icinga\Exception\ProgrammingError;
use Exception;
@ -30,6 +31,7 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
protected $type;
/* key/value!! */
protected $booleans = array();
private $vars;
@ -370,6 +372,35 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
return $vals;
}
public function matches(Filter $filter)
{
return $filter->matches($this->flattenProperties());
}
protected function flattenProperties()
{
$db = $this->getDb();
$obj = (object) array();
foreach ($this->getProperties() as $k => $v) {
$obj->$k = $v;
}
if ($this->supportsCustomVars()) {
/*
foreach ($this->getVars() as $k => $v) {
$obj->{'vars.' . $k} = $v;
}
*/
}
return $obj;
}
public function cloneFullyResolved()
{
// TODO
}
protected function assertCustomVarsSupport()
{
if (! $this->supportsCustomVars()) {