From a1e4e6e92b11c9b57037a65ff19e184c04ca19f4 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 15 Jun 2015 16:05:37 +0200 Subject: [PATCH] ObjectList: Implement interface Filterable Allows to use instances of it for Controller::applyRestriction(). refs #9009 --- .../library/Monitoring/Object/ObjectList.php | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/modules/monitoring/library/Monitoring/Object/ObjectList.php b/modules/monitoring/library/Monitoring/Object/ObjectList.php index c4ecdddb2..f2e51daf2 100644 --- a/modules/monitoring/library/Monitoring/Object/ObjectList.php +++ b/modules/monitoring/library/Monitoring/Object/ObjectList.php @@ -6,10 +6,11 @@ namespace Icinga\Module\Monitoring\Object; use ArrayIterator; use Countable; use Icinga\Data\Filter\Filter; +use Icinga\Data\Filterable; use IteratorAggregate; use Icinga\Module\Monitoring\Backend\MonitoringBackend; -abstract class ObjectList implements Countable, IteratorAggregate +abstract class ObjectList implements Countable, IteratorAggregate, Filterable { /** * @var string @@ -81,9 +82,29 @@ abstract class ObjectList implements Countable, IteratorAggregate */ public function getFilter() { + if ($this->filter === null) { + $this->filter = Filter::matchAny(); + } + 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(); /**