SPL-StandardPHPLibrary
dbareader.inc
Go to the documentation of this file.
1 <?php
2 
17 class DbaReader implements Iterator
18 {
19 
20  protected $db = NULL;
21  private $key = false;
22  private $val = false;
23 
30  function __construct($file, $handler) {
31  if (!$this->db = dba_open($file, 'r', $handler)) {
32  throw new exception('Could not open file ' . $file);
33  }
34  }
35 
39  function __destruct() {
40  dba_close($this->db);
41  }
42 
46  function rewind() {
47  $this->key = dba_firstkey($this->db);
48  $this->fetch_data();
49  }
50 
56  function next() {
57  $this->key = dba_nextkey($this->db);
58  $this->fetch_data();
59  }
60 
64  private function fetch_data() {
65  if ($this->key !== false) {
66  $this->val = dba_fetch($this->key, $this->db);
67  }
68  }
69 
73  function current() {
74  return $this->val;
75  }
76 
80  function valid() {
81  if ($this->db && $this->key !== false) {
82  return true;
83  } else {
84  return false;
85  }
86  }
87 
91  function key() {
92  return $this->key;
93  }
94 }
95 
96 ?>
__destruct()
Close database.
Definition: dbareader.inc:39
__construct($file, $handler)
Open database $file with $handler in read only mode.
Definition: dbareader.inc:30
next()
Move to next element.
Definition: dbareader.inc:56
This implements a DBA Iterator.
Definition: dbareader.inc:17
fetch_data()
Fetches the current data if $key is valid.
Definition: dbareader.inc:64
Basic iterator.
Definition: spl.php:549
rewind()
Rewind to first element.
Definition: dbareader.inc:46