From c4dd7a1a684490673e25aaf4fabec5df138854c4 Mon Sep 17 00:00:00 2001 From: Lorry Tar Creator Date: Thu, 14 Mar 2013 05:42:27 +0000 Subject: Imported from /home/lorry/working-area/delta_php2/php-5.4.13.tar.bz2. --- ext/spl/examples/dbareader.inc | 96 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 ext/spl/examples/dbareader.inc (limited to 'ext/spl/examples/dbareader.inc') diff --git a/ext/spl/examples/dbareader.inc b/ext/spl/examples/dbareader.inc new file mode 100644 index 0000000..b097912 --- /dev/null +++ b/ext/spl/examples/dbareader.inc @@ -0,0 +1,96 @@ +db = dba_open($file, 'r', $handler)) { + throw new exception('Could not open file ' . $file); + } + } + + /** + * Close database. + */ + function __destruct() { + dba_close($this->db); + } + + /** + * Rewind to first element. + */ + function rewind() { + $this->key = dba_firstkey($this->db); + $this->fetch_data(); + } + + /** + * Move to next element. + * + * @return void + */ + function next() { + $this->key = dba_nextkey($this->db); + $this->fetch_data(); + } + + /** + * Fetches the current data if $key is valid + */ + private function fetch_data() { + if ($this->key !== false) { + $this->val = dba_fetch($this->key, $this->db); + } + } + + /** + * @return Current data. + */ + function current() { + return $this->val; + } + + /** + * @return Whether more elements are available. + */ + function valid() { + if ($this->db && $this->key !== false) { + return true; + } else { + return false; + } + } + + /** + * @return Current key. + */ + function key() { + return $this->key; + } +} + +?> \ No newline at end of file -- cgit v1.2.1