SPL-StandardPHPLibrary
Public Member Functions | Protected Attributes
DbaArray Class Reference
Inheritance diagram for DbaArray:
Inheritance graph
[legend]
Collaboration diagram for DbaArray:
Collaboration graph
[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:
fileDatabase file to open.
handlerHandler to use for database access.

Reimplemented from DbaReader.

Definition at line 28 of file dbaarray.inc.

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

Close database.

Reimplemented from DbaReader.

Definition at line 39 of file dbaarray.inc.


Member Function Documentation

DbaReader::current ( ) [inherited]
Returns:
Current data.

Implements Iterator.

Definition at line 73 of file dbareader.inc.

                       {
        return $this->val;
    }
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().

                   {
        return $this->key;
    }
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().

                    {
        $this->key = dba_nextkey($this->db);
        $this->fetch_data();
    }

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.

    {
        return dba_exists($name, $this->db);
    }
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.

    {
        $data = dba_fetch($name, $this->db); 
        if($data) {
            //return unserialize($data);
            return $data;
        }
        else 
        {
            return NULL;
        }
    }
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.

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

Delete a key/value pair.

Parameters:
$namekey to delete.

Implements ArrayAccess.

Definition at line 89 of file dbaarray.inc.

    {
        return dba_delete($name, $this->db);
    }
DbaReader::rewind ( ) [inherited]

Rewind to first element.

Implements Iterator.

Definition at line 46 of file dbareader.inc.

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

                      {
        $this->key = dba_firstkey($this->db);
        $this->fetch_data();
    }

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

                     {
        if ($this->db && $this->key !== false) {
            return true;
        } else {
            return false;
        }
    }

Here is the call graph for this function:


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: