ObjectList: Implement interface Filterable

Allows to use instances of it for Controller::applyRestriction().

refs #9009
This commit is contained in:
Johannes Meyer 2015-06-15 16:05:37 +02:00
parent ede8cc5e83
commit a1e4e6e92b
1 changed files with 22 additions and 1 deletions

View File

@ -6,10 +6,11 @@ namespace Icinga\Module\Monitoring\Object;
use ArrayIterator; use ArrayIterator;
use Countable; use Countable;
use Icinga\Data\Filter\Filter; use Icinga\Data\Filter\Filter;
use Icinga\Data\Filterable;
use IteratorAggregate; use IteratorAggregate;
use Icinga\Module\Monitoring\Backend\MonitoringBackend; use Icinga\Module\Monitoring\Backend\MonitoringBackend;
abstract class ObjectList implements Countable, IteratorAggregate abstract class ObjectList implements Countable, IteratorAggregate, Filterable
{ {
/** /**
* @var string * @var string
@ -81,9 +82,29 @@ abstract class ObjectList implements Countable, IteratorAggregate
*/ */
public function getFilter() public function getFilter()
{ {
if ($this->filter === null) {
$this->filter = Filter::matchAny();
}
return $this->filter; return $this->filter;
} }
public function applyFilter(Filter $filter)
{
$this->getFilter()->addFilter($filter);
return $this;
}
public function addFilter(Filter $filter)
{
$this->getFilter()->addFilter($filter);
}
public function where($condition, $value = null)
{
$this->getFilter()->addFilter(Filter::where($condition, $value));
}
abstract protected function fetchObjects(); abstract protected function fetchObjects();
/** /**