DbaArray Class Reference
[Example classes]

This implements a DBA Array. More...

Inheritance diagram for DbaArray:

Inheritance graph
{DbaReader\n|# $db\l- $key\l- $val\l|+ __construct()\l+ __destruct()\l+ current()\l+ key()\l+ next()\l+ rewind()\l+ valid()\l- fetch_data()\l}{Iterator\n||+ current()\l+ key()\l+ next()\l+ rewind()\l+ valid()\l}{Traversable\n||}{ArrayAccess\n||+ offsetExists()\l+ offsetGet()\l+ offsetSet()\l+ offsetUnset()\l}
[legend]
Collaboration diagram for DbaArray:

Collaboration graph
{DbaReader\n|# $db\l- $key\l- $val\l|+ __construct()\l+ __destruct()\l+ current()\l+ key()\l+ next()\l+ rewind()\l+ valid()\l- fetch_data()\l}{Iterator\n||+ current()\l+ key()\l+ next()\l+ rewind()\l+ valid()\l}{Traversable\n||}{ArrayAccess\n||+ offsetExists()\l+ offsetGet()\l+ offsetSet()\l+ offsetUnset()\l}
[legend]
List of all members.

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:
file Database file to open.
handler Handler to use for database access.

Reimplemented from DbaReader.

Definition at line 28 of file dbaarray.inc.

00029     {
00030         $this->db = dba_popen($file, "c", $handler);
00031         if (!$this->db) {
00032             throw new exception("Databse could not be opened");
00033         }
00034     }

DbaArray::__destruct (  ) 

Close database.

Reimplemented from DbaReader.

Definition at line 39 of file dbaarray.inc.

00040     {
00041         parent::__destruct();
00042     }


Member Function Documentation

DbaReader::current (  )  [inherited]

Returns:
Current data.

Implements Iterator.

Definition at line 73 of file dbareader.inc.

00073                        {
00074         return $this->val;
00075     }

DbaReader::key (  )  [inherited]

Returns:
Current key.

Implements Iterator.

Definition at line 91 of file dbareader.inc.

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

00091                    {
00092         return $this->key;
00093     }

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().

00056                     {
00057         $this->key = dba_nextkey($this->db);
00058         $this->fetch_data();
00059     }

Here is the call graph for this function:

DbaReader::fetch_dataDbaReader::key

DbaArray::offsetExists ( name  ) 

Returns:
whether key $name exists.

Implements ArrayAccess.

Definition at line 82 of file dbaarray.inc.

00083     {
00084         return dba_exists($name, $this->db);
00085     }

DbaArray::offsetGet ( name  ) 

Read an entry.

Parameters:
$name key to read from
Returns:
value associated with $name

Implements ArrayAccess.

Definition at line 50 of file dbaarray.inc.

00051     {
00052         $data = dba_fetch($name, $this->db); 
00053         if($data) {
00054             if (ini_get('magic_quotes_runtime')) {
00055                 $data = stripslashes($data);
00056             }
00057             //return unserialize($data);
00058             return $data;
00059         }
00060         else 
00061         {
00062             return NULL;
00063         }
00064     }

DbaArray::offsetSet ( name,
value 
)

Set an entry.

Parameters:
$name key to write to
$value value to write

Implements ArrayAccess.

Definition at line 72 of file dbaarray.inc.

00073     {
00074         //dba_replace($name, serialize($value), $this->db);
00075         dba_replace($name, $value, $this->db);
00076         return $value;
00077     }

DbaArray::offsetUnset ( name  ) 

Delete a key/value pair.

Parameters:
$name key to delete.

Implements ArrayAccess.

Definition at line 92 of file dbaarray.inc.

00093     {
00094         return dba_delete($name, $this->db);
00095     }

DbaReader::rewind (  )  [inherited]

Rewind to first element.

Implements Iterator.

Definition at line 46 of file dbareader.inc.

References DbaReader::fetch_data(), and DbaReader::key().

00046                       {
00047         $this->key = dba_firstkey($this->db);
00048         $this->fetch_data();
00049     }

Here is the call graph for this function:

DbaReader::fetch_dataDbaReader::key

DbaReader::valid (  )  [inherited]

Returns:
Whether more elements are available.

Implements Iterator.

Definition at line 80 of file dbareader.inc.

References DbaReader::key().

00080                      {
00081         if ($this->db && $this->key !== false) {
00082             return true;
00083         } else {
00084             return false;
00085         }
00086     }

Here is the call graph for this function:

DbaReader::key


Member Data Documentation

DbaReader::$db = NULL [protected, inherited]

Definition at line 20 of file dbareader.inc.


The documentation for this class was generated from the following file:
Generated on Thu Apr 26 01:05:20 2007 for SPL-StandardPHPLibrary by  doxygen 1.5.2