. */ namespace Volkszaehler; /** * @author Steffen Vogel */ use Doctrine\DBAL; class DataIterator implements \Iterator, \Countable { protected $current; protected $key; // incrementing key protected $pdoStmt; // PDOStatement protected $size; // total readings in PDOStatement public function __construct(DBAL\Statement $stmt, $size) { $this->size = $size; $this->pdoStmt = $stmt->getWrappedStatement(); $this->pdoStmt->setFetchMode(\PDO::FETCH_NUM); } public function current() { return $this->current; } public function next() { $this->key++; $this->current = $this->pdoStmt->fetch(); } public function key() { return $this->key; } public function valid() { return (boolean) $this->current; } /** * NoRewindIterator */ public function rewind() { $this->key = 0; $this->current = $this->pdoStmt->fetch(); } public function count() { return $this->size; } } ?>