2003-07-16 21:52:03 +00:00
|
|
|
<?php
|
|
|
|
|
2004-05-10 17:26:03 +00:00
|
|
|
/** @file dbareader.inc
|
|
|
|
* @ingroup Examples
|
|
|
|
* @brief class DbaReader
|
|
|
|
* @author Marcus Boerger
|
|
|
|
* @date 2003 - 2004
|
|
|
|
*
|
|
|
|
* SPL - Standard PHP Library
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** @ingroup Examples
|
2004-05-08 12:24:15 +00:00
|
|
|
* @brief This implements a DBA Iterator.
|
2003-07-16 21:52:03 +00:00
|
|
|
* @author Marcus Boerger
|
|
|
|
* @version 1.0
|
|
|
|
*/
|
2003-11-22 20:51:15 +00:00
|
|
|
class DbaReader implements Iterator
|
2003-07-16 21:52:03 +00:00
|
|
|
{
|
|
|
|
|
2004-05-08 12:24:15 +00:00
|
|
|
protected $db = NULL;
|
2003-07-16 21:52:03 +00:00
|
|
|
private $key = false;
|
|
|
|
private $val = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Open database $file with $handler in read only mode.
|
|
|
|
*
|
|
|
|
* @param file Database file to open.
|
|
|
|
* @param handler Handler to use for database access.
|
|
|
|
*/
|
|
|
|
function __construct($file, $handler) {
|
|
|
|
$this->db = dba_open($file, 'r', $handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Close database.
|
|
|
|
*/
|
|
|
|
function __destruct() {
|
|
|
|
if ($this->db) {
|
|
|
|
dba_close($this->db);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Rewind to first element.
|
|
|
|
*/
|
|
|
|
function rewind() {
|
|
|
|
if ($this->db) {
|
|
|
|
$this->key = dba_firstkey($this->db);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Current data.
|
|
|
|
*/
|
|
|
|
function current() {
|
|
|
|
return $this->val;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Move to next element.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function next() {
|
|
|
|
if ($this->db) {
|
|
|
|
$this->key = dba_nextkey($this->db);
|
|
|
|
if ($this->key !== false) {
|
|
|
|
$this->val = dba_fetch($this->key, $this->db);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Whether more elements are available.
|
|
|
|
*/
|
2004-03-08 17:33:31 +00:00
|
|
|
function valid() {
|
2003-07-16 21:52:03 +00:00
|
|
|
if ($this->db && $this->key !== false) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Current key.
|
|
|
|
*/
|
|
|
|
function key() {
|
|
|
|
return $this->key;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|