From ed5f646b6ff2bb4781f7360998dc6db45084fb0e Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Fri, 15 May 2015 14:26:00 +0200 Subject: [PATCH] SimpleQuery: Implement interface IteratorAggregate I'd like to foreach such. --- library/Icinga/Data/SimpleQuery.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/library/Icinga/Data/SimpleQuery.php b/library/Icinga/Data/SimpleQuery.php index 16f82cbe4..20d514ecf 100644 --- a/library/Icinga/Data/SimpleQuery.php +++ b/library/Icinga/Data/SimpleQuery.php @@ -4,13 +4,15 @@ namespace Icinga\Data; use Icinga\Application\Icinga; +use ArrayIterator; +use IteratorAggregate; use Icinga\Data\Filter\Filter; use Icinga\Web\Paginator\Adapter\QueryAdapter; use Zend_Paginator; use Exception; use Icinga\Exception\IcingaException; -class SimpleQuery implements QueryInterface, Queryable +class SimpleQuery implements QueryInterface, Queryable, IteratorAggregate { /** * Query data source @@ -91,6 +93,16 @@ class SimpleQuery implements QueryInterface, Queryable */ protected function init() {} + /** + * Return a iterable for this query's result + * + * @return ArrayIterator + */ + public function getIterator() + { + return new ArrayIterator($this->fetchAll()); + } + /** * Get the data source *