<?php
class DbaReader implements Iterator
{
protected $db = NULL;
private $key = false;
private $val = false;
function __construct($file, $handler) {
if (!$this->db = dba_open($file, 'r', $handler)) {
throw new exception('Could not open file ' . $file);
}
}
function __destruct() {
dba_close($this->db);
}
function rewind() {
$this->key = dba_firstkey($this->db);
$this->fetch_data();
}
function next() {
$this->key = dba_nextkey($this->db);
$this->fetch_data();
}
private function fetch_data() {
if ($this->key !== false) {
$this->val = dba_fetch($this->key, $this->db);
}
}
function current() {
return $this->val;
}
function valid() {
if ($this->db && $this->key !== false) {
return true;
} else {
return false;
}
}
function key() {
return $this->key;
}
}
?>