Add PlEmptyIterator
authorRaphaël Barrois <raphael.barrois@polytechnique.org>
Thu, 18 Mar 2010 20:45:30 +0000 (21:45 +0100)
committerRaphaël Barrois <raphael.barrois@polytechnique.org>
Mon, 22 Mar 2010 12:51:17 +0000 (13:51 +0100)
Signed-off-by: Raphaël Barrois <raphael.barrois@polytechnique.org>
classes/pliteratorutils.php

index 930cc56..a77244b 100644 (file)
 
 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