From c291ca5486bce705cd3dfd81065cbd2d92b96da5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Barrois?= Date: Thu, 18 Mar 2010 21:45:30 +0100 Subject: [PATCH] Add PlEmptyIterator MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Raphaël Barrois --- classes/pliteratorutils.php | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/classes/pliteratorutils.php b/classes/pliteratorutils.php index 930cc56..a77244b 100644 --- a/classes/pliteratorutils.php +++ b/classes/pliteratorutils.php @@ -21,6 +21,13 @@ class PlIteratorUtils { + /** Builds a new empty iterator + */ + public static function emptyIterator() + { + return new PlEmptyIterator(); + } + /** Build an iterator over an array. * @param array The array. * @param depth The depth of iteration. @@ -130,6 +137,31 @@ class PlIteratorUtils } } +/** Empty iterator + */ +class PlEmptyIterator implements PlIterator +{ + public function first() + { + return false; + } + + public function last() + { + return false; + } + + public function next() + { + return null; + } + + public function total() + { + return 0; + } +} + /** Iterates over an array. */ class PlArrayIterator implements PlIterator -- 2.1.4