SPL-StandardPHPLibrary
Public Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
DbaReader Class Reference
Inheritance diagram for DbaReader:
Inheritance graph
Collaboration diagram for DbaReader:
Collaboration graph

Public Member Functions

 __construct ($file, $handler)
 
 __destruct ()
 
 current ()
 
 key ()
 
 next ()
 
 rewind ()
 
 valid ()
 

Protected Attributes

 $db = NULL
 

Private Member Functions

 fetch_data ()
 

Private Attributes

 $key = false
 
 $val = false
 

Detailed Description

This implements a DBA Iterator.

Author
Marcus Boerger
Version
1.0

Definition at line 17 of file dbareader.inc.

Constructor & Destructor Documentation

DbaReader::__construct (   $file,
  $handler 
)

Open database $file with $handler in read only mode.

Parameters
fileDatabase file to open.
handlerHandler to use for database access.

Definition at line 30 of file dbareader.inc.

30  {
31  if (!$this->db = dba_open($file, 'r', $handler)) {
32  throw new exception('Could not open file ' . $file);
33  }
34  }
DbaReader::__destruct ( )

Close database.

Definition at line 39 of file dbareader.inc.

39  {
40  dba_close($this->db);
41  }

Member Function Documentation

DbaReader::current ( )
Returns
Current data.

Implements Iterator.

Definition at line 73 of file dbareader.inc.

References $val.

73  {
74  return $this->val;
75  }
DbaReader::fetch_data ( )
private

Fetches the current data if $key is valid.

Definition at line 64 of file dbareader.inc.

References key().

Referenced by next(), and rewind().

64  {
65  if ($this->key !== false) {
66  $this->val = dba_fetch($this->key, $this->db);
67  }
68  }

Here is the call graph for this function:

DbaReader::key ( )
Returns
Current key.

Implements Iterator.

Definition at line 91 of file dbareader.inc.

References $key.

Referenced by fetch_data(), next(), rewind(), and valid().

91  {
92  return $this->key;
93  }
DbaReader::next ( )

Move to next element.

Returns
void

Implements Iterator.

Definition at line 56 of file dbareader.inc.

References fetch_data(), and key().

56  {
57  $this->key = dba_nextkey($this->db);
58  $this->fetch_data();
59  }
fetch_data()
Fetches the current data if $key is valid.
Definition: dbareader.inc:64

Here is the call graph for this function:

DbaReader::rewind ( )

Rewind to first element.

Implements Iterator.

Definition at line 46 of file dbareader.inc.

References fetch_data(), and key().

46  {
47  $this->key = dba_firstkey($this->db);
48  $this->fetch_data();
49  }
fetch_data()
Fetches the current data if $key is valid.
Definition: dbareader.inc:64

Here is the call graph for this function:

DbaReader::valid ( )
Returns
Whether more elements are available.

Implements Iterator.

Definition at line 80 of file dbareader.inc.

References key().

80  {
81  if ($this->db && $this->key !== false) {
82  return true;
83  } else {
84  return false;
85  }
86  }

Here is the call graph for this function:

Member Data Documentation

DbaReader::$db = NULL
protected

Definition at line 20 of file dbareader.inc.

DbaReader::$key = false
private

Definition at line 21 of file dbareader.inc.

Referenced by key().

DbaReader::$val = false
private

Definition at line 22 of file dbareader.inc.

Referenced by current().


The documentation for this class was generated from the following file: