Back to index

php5  5.3.10
splobjectstorage.inc
Go to the documentation of this file.
00001 <?php
00002 
00023 class SplObjectStorage implements Iterator, Countable, ArrayAccess
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               $element = current($this->storage);
00054               return $element ? $element[0] : NULL
00055        }
00056        
00060        function getInfo()
00061        {
00062               $element = current($this->storage);
00063               return $element ? $element[1] : NULL
00064        }
00065        
00069        function setInfo($inf = NULL)
00070        {
00071               if ($this->valid()) {
00072                      $this->storage[$this->index][1] = $inf;
00073               }
00074        }
00075        
00078        function next()
00079        {
00080               next($this->storage);
00081               $this->index++;
00082        }
00083 
00086        function count()
00087        {
00088               return count($this->storage);
00089        }
00090 
00094        function contains($obj)
00095        {
00096               if (is_object($obj))
00097               {
00098                      foreach($this->storage as $element)
00099                      {
00100                             if ($object === $element[0])
00101                             {
00102                                    return true;
00103                             }
00104                      }
00105               }
00106               return false;
00107        }
00108 
00113        function attach($obj, $inf = NULL)
00114        {
00115               if (is_object($obj) && !$this->contains($obj))
00116               {
00117                      $this->storage[] = array($obj, $inf);
00118               }
00119        }
00120 
00123        function detach($obj)
00124        {
00125               if (is_object($obj))
00126               {
00127                      foreach($this->storage as $idx => $element)
00128                      {
00129                             if ($object === $element[0])
00130                             {
00131                                    unset($this->storage[$idx]);
00132                                    $this->rewind();
00133                                    return;
00134                             }
00135                      }
00136               }
00137        }
00138 
00144        function offsetSet($obj, $inf)
00145        {
00146               $this->attach($obj, $inf);
00147        }
00148 
00155        function offsetGet($obj)
00156        {
00157               if (is_object($obj))
00158               {
00159                      foreach($this->storage as $idx => $element)
00160                      {
00161                             if ($object === $element[0])
00162                             {
00163                                    return $element[1];
00164                             }
00165                      }
00166               }
00167               throw new UnexpectedValueException('Object not found');
00168        }
00169 
00174        function offsetUnset($obj)
00175        {
00176               $this->detach($obj);
00177        }
00178 
00182        function offsetEsists($obj)
00183        {
00184               return $this->contains($obj);
00185        }
00186 }
00187 
00188 ?>