Back to index

php5  5.3.10
Public Member Functions | Private Attributes
SplObjectStorage Class Reference

Object storage. More...

Inheritance diagram for SplObjectStorage:
Inheritance graph
[legend]
Collaboration diagram for SplObjectStorage:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 rewind ()
 Rewind to top iterator as set in constructor.
 valid ()
 key ()
 current ()
 getInfo ()
 setInfo ($inf=NULL)
 next ()
 Forward to next element.
 count ()
 contains ($obj)
 attach ($obj, $inf=NULL)
 detach ($obj)
 offsetSet ($obj, $inf)
 offsetGet ($obj)
 offsetUnset ($obj)
 offsetEsists ($obj)
 offsetExists ($offset)

Private Attributes

 $storage = array()
 $index = 0

Detailed Description

Object storage.

Author:
Marcus Boerger
Version:
1.1
Since:
PHP 5.1.2

This container allows to store objects uniquly without the need to compare them one by one. This is only possible internally. The code represenation here therefore has a complexity of O(n) while the actual implementation has complexity O(1).

Definition at line 23 of file splobjectstorage.inc.


Member Function Documentation

SplObjectStorage::attach ( obj,
inf = NULL 
)
Parameters:
$objnew object to attach to storage or object whose associative information is to be replaced
$infassociative information stored along the object

Definition at line 113 of file splobjectstorage.inc.

       {
              if (is_object($obj) && !$this->contains($obj))
              {
                     $this->storage[] = array($obj, $inf);
              }
       }

Here is the call graph for this function:

Here is the caller graph for this function:

Parameters:
$objobject to look for
Returns:
whether $obj is contained in storage

Definition at line 94 of file splobjectstorage.inc.

       {
              if (is_object($obj))
              {
                     foreach($this->storage as $element)
                     {
                            if ($object === $element[0])
                            {
                                   return true;
                            }
                     }
              }
              return false;
       }

Here is the caller graph for this function:

Returns:
number of objects in storage

Implements Countable.

Definition at line 86 of file splobjectstorage.inc.

       {
              return count($this->storage);
       }
Returns:
current object

Implements Iterator.

Definition at line 51 of file splobjectstorage.inc.

       {
              $element = current($this->storage);
              return $element ? $element[0] : NULL
       }

Here is the caller graph for this function:

Parameters:
$objobject to remove from storage

Definition at line 123 of file splobjectstorage.inc.

       {
              if (is_object($obj))
              {
                     foreach($this->storage as $idx => $element)
                     {
                            if ($object === $element[0])
                            {
                                   unset($this->storage[$idx]);
                                   $this->rewind();
                                   return;
                            }
                     }
              }
       }

Here is the call graph for this function:

Here is the caller graph for this function:

Returns:
get current object's associated information
Since:
5.3.0

Definition at line 60 of file splobjectstorage.inc.

       {
              $element = current($this->storage);
              return $element ? $element[1] : NULL
       }

Here is the call graph for this function:

Returns:
current key

Implements Iterator.

Definition at line 44 of file splobjectstorage.inc.

       {
              return $this->index;
       }

Here is the caller graph for this function:

Forward to next element.

Implements Iterator.

Definition at line 78 of file splobjectstorage.inc.

       {
              next($this->storage);
              $this->index++;
       }
Parameters:
$objobject to look for
Returns:
whether $obj is contained in storage

Definition at line 182 of file splobjectstorage.inc.

       {
              return $this->contains($obj);
       }

Here is the call graph for this function:

ArrayAccess::offsetExists ( offset) [inherited]
Parameters:
$offsetto check
Returns:
whether the offset exists.

Implemented in ArrayIterator, ArrayObject, SplDoublyLinkedList, and DbaArray.

Parameters:
$objExising object to look for
Returns:
associative information stored with object
Exceptions:
UnexpectedValueExceptionif Object $obj is not contained in storage
Since:
5.3.0

Implements ArrayAccess.

Definition at line 155 of file splobjectstorage.inc.

       {
              if (is_object($obj))
              {
                     foreach($this->storage as $idx => $element)
                     {
                            if ($object === $element[0])
                            {
                                   return $element[1];
                            }
                     }
              }
              throw new UnexpectedValueException('Object not found');
       }
SplObjectStorage::offsetSet ( obj,
inf 
)
Parameters:
$objnew object to attach to storage or object whose associative information is to be replaced
$infassociative information stored along the object
Since:
5.3.0

Implements ArrayAccess.

Definition at line 144 of file splobjectstorage.inc.

       {
              $this->attach($obj, $inf);
       }

Here is the call graph for this function:

Parameters:
$objExising object to look for
Returns:
associative information stored with object
Since:
5.3.0

Implements ArrayAccess.

Definition at line 174 of file splobjectstorage.inc.

       {
              $this->detach($obj);
       }

Here is the call graph for this function:

Rewind to top iterator as set in constructor.

Implements Iterator.

Definition at line 30 of file splobjectstorage.inc.

       {
              rewind($this->storage);
       }

Here is the caller graph for this function:

Returns:
set current object's associated information
Since:
5.3.0

Definition at line 69 of file splobjectstorage.inc.

       {
              if ($this->valid()) {
                     $this->storage[$this->index][1] = $inf;
              }
       }

Here is the call graph for this function:

Returns:
whether iterator is valid

Implements Iterator.

Definition at line 37 of file splobjectstorage.inc.

       {
              return key($this->storage) !== false;
       }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

SplObjectStorage::$index = 0 [private]

Definition at line 26 of file splobjectstorage.inc.

SplObjectStorage::$storage = array() [private]

Definition at line 25 of file splobjectstorage.inc.


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