fix direct iterator usage (don't return an initial null)
authorChuck Hagenbuch <chuck@horde.org>
Tue, 16 Jun 2009 02:56:21 +0000 (22:56 -0400)
committerChuck Hagenbuch <chuck@horde.org>
Tue, 16 Jun 2009 02:56:21 +0000 (22:56 -0400)
framework/Db/lib/Horde/Db/StatementParser.php

index 84885e7..562269a 100644 (file)
  */
 class Horde_Db_StatementParser implements Iterator
 {
-    private $_count;
-    private $_currentStatement;
+    protected $_count = 0;
+    protected $_currentStatement;
 
-    public function __construct(SplFileObject $file)
+    public function __construct($file)
     {
+        if (is_string($file)) {
+            $file = new SplFileObject($file, 'r');
+        }
         $this->_file = $file;
-        $this->_count = 0;
     }
 
     public function current()
     {
+        if (is_null($this->_currentStatement)) {
+            $this->rewind();
+        }
         return $this->_currentStatement;
     }
 
     public function key()
     {
+        if (is_null($this->_currentStatement)) {
+            $this->rewind();
+        }
         return $this->_count;
     }
 
@@ -51,7 +59,9 @@ class Horde_Db_StatementParser implements Iterator
     public function rewind()
     {
         $this->_count = 0;
-        return $this->_file->rewind();
+        $this->_currentStatement = null;
+        $this->_file->rewind();
+        $this->next();
     }
 
     public function valid()