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

Public Member Functions

 __construct ($file, $handler)
 
 __destruct ()
 
 current ()
 
 key ()
 
 next ()
 
 offsetExists ($name)
 
 offsetGet ($name)
 
 offsetSet ($name, $value)
 
 offsetUnset ($name)
 
 rewind ()
 
 valid ()
 

Protected Attributes

 $db = NULL
 

Detailed Description

This implements a DBA Array.

Author
Marcus Boerger
Version
1.0

Definition at line 19 of file dbaarray.inc.

Constructor & Destructor Documentation

DbaArray::__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 28 of file dbaarray.inc.

29  {
30  $this->db = dba_popen($file, "c", $handler);
31  if (!$this->db) {
32  throw new exception("Databse could not be opened");
33  }
34  }
DbaArray::__destruct ( )

Close database.

Definition at line 39 of file dbaarray.inc.

40  {
41  parent::__destruct();
42  }

Member Function Documentation

DbaReader::current ( )
inherited
Returns
Current data.

Implements Iterator.

Definition at line 73 of file dbareader.inc.

References DbaReader\$val.

73  {
74  return $this->val;
75  }
DbaReader::key ( )
inherited
Returns
Current key.

Implements Iterator.

Definition at line 91 of file dbareader.inc.

References DbaReader\$key.

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

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

Move to next element.

Returns
void

Implements Iterator.

Definition at line 56 of file dbareader.inc.

References DbaReader\fetch_data(), and DbaReader\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:

DbaArray::offsetExists (   $name)
Returns
whether key $name exists.

Implements ArrayAccess.

Definition at line 79 of file dbaarray.inc.

80  {
81  return dba_exists($name, $this->db);
82  }
DbaArray::offsetGet (   $name)

Read an entry.

Parameters
$namekey to read from
Returns
value associated with $name

Implements ArrayAccess.

Definition at line 50 of file dbaarray.inc.

51  {
52  $data = dba_fetch($name, $this->db);
53  if($data) {
54  //return unserialize($data);
55  return $data;
56  }
57  else
58  {
59  return NULL;
60  }
61  }
DbaArray::offsetSet (   $name,
  $value 
)

Set an entry.

Parameters
$namekey to write to
$valuevalue to write

Implements ArrayAccess.

Definition at line 69 of file dbaarray.inc.

70  {
71  //dba_replace($name, serialize($value), $this->db);
72  dba_replace($name, $value, $this->db);
73  return $value;
74  }
DbaArray::offsetUnset (   $name)

Delete a key/value pair.

Parameters
$namekey to delete.

Implements ArrayAccess.

Definition at line 89 of file dbaarray.inc.

90  {
91  return dba_delete($name, $this->db);
92  }
DbaReader::rewind ( )
inherited

Rewind to first element.

Implements Iterator.

Definition at line 46 of file dbareader.inc.

References DbaReader\fetch_data(), and DbaReader\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 ( )
inherited
Returns
Whether more elements are available.

Implements Iterator.

Definition at line 80 of file dbareader.inc.

References DbaReader\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
protectedinherited

Definition at line 20 of file dbareader.inc.


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