splobjectstorage.inc

Go to the documentation of this file.
00001 <?php
00002 
00023 class SplObjectStorage implements Iterator, Countable
00024 {
00025     private $storage = array();
00026     private $index = 0;
00027 
00030     function rewind()
00031     {
00032         rewind($this->storage);
00033     }
00034     
00037     function valid()
00038     {
00039         return key($this->storage) !== false;
00040     }
00041     
00044     function key()
00045     {
00046         return $this->index;
00047     }
00048     
00051     function current()
00052     {
00053         return current($this->storage);
00054     }
00055     
00058     function next()
00059     {
00060         next($this->storage);
00061         $this->index++;
00062     }
00063 
00066     function count()
00067     {
00068         return count($this->storage);
00069     }
00070 
00074     function contains($obj)
00075     {
00076         if (is_object($obj))
00077         {
00078             foreach($this->storage as $object)
00079             {
00080                 if ($object === $obj)
00081                 {
00082                     return true;
00083                 }
00084             }
00085         }
00086         return false;
00087     }
00088 
00091     function attach($obj)
00092     {
00093         if (is_object($obj) && !$this->contains($obj))
00094         {
00095             $this->storage[] = $obj;
00096         }
00097     }
00098 
00101     function detach($obj)
00102     {
00103         if (is_object($obj))
00104         {
00105             foreach($this->storage as $idx => $object)
00106             {
00107                 if ($object === $obj)
00108                 {
00109                     unset($this->storage[$idx]);
00110                     $this->rewind();
00111                     return;
00112                 }
00113             }
00114         }
00115     }
00116 }
00117 
00118 ?>

Generated on Thu Apr 26 01:04:48 2007 for SPL-StandardPHPLibrary by  doxygen 1.5.2