10 defined(
'JPATH_PLATFORM') or die;
28 private $_current =
false;
36 private $_objects = array();
46 public function __construct(array $objects = array())
49 $this->_initialise($objects);
69 public function __call($method, $arguments = array())
74 foreach ($this->_objects as $key => $object)
77 $callback = array($object, $method);
80 if (is_callable($callback))
83 $return[$key] = call_user_func_array($callback, $arguments);
106 public function __get($property)
111 foreach ($this->_objects as $key => $object)
114 $return[$key] = $object->$property;
131 public function __isset($property)
136 foreach ($this->_objects as $object)
139 $return[] = isset($object->$property);
142 return in_array(
true, $return,
true) ?
true :
false;
160 public function __set($property, $value)
163 foreach ($this->_objects as $object)
166 $object->$property = $value;
183 public function __unset($property)
186 foreach ($this->_objects as $object)
188 unset($object->$property);
199 public function count()
201 return count($this->_objects);
211 public function clear()
213 $this->_objects = array();
226 public function current()
228 return is_scalar($this->_current) ? $this->_objects[$this->_current] :
false;
244 public function dump($depth = 3, SplObjectStorage $dumped = null)
247 if ($dumped === null)
249 $dumped =
new SplObjectStorage;
253 $dumped->attach($this);
261 foreach ($this->_objects as $key => $object)
263 $objects[$key] = $object->dump($depth, $dumped);
283 public function jsonSerialize($serialized = null)
286 if ($serialized === null)
288 $serialized = array();
292 $serialized[] = spl_object_hash($this);
296 foreach ($this->_objects as $object)
299 $return[] = $object->jsonSerialize($serialized);
312 public function key()
314 return $this->_current;
324 public function keys()
326 return array_keys($this->_objects);
336 public function next()
339 $keys = $this->keys();
342 if ($this->_current ===
false && isset($keys[0]))
345 $this->_current = $keys[0];
350 $position = array_search($this->_current, $keys);
353 if ($position !==
false && isset($keys[$position + 1]))
356 $this->_current = $keys[$position + 1];
361 $this->_current = null;
375 public function offsetExists($offset)
377 return isset($this->_objects[$offset]);
389 public function offsetGet($offset)
391 return isset($this->_objects[$offset]) ? $this->_objects[$offset] : null;
405 public function offsetSet($offset, $object)
408 if (!($object instanceof
JData))
410 throw new InvalidArgumentException(sprintf(
'%s("%s", *%s*)', __METHOD__, $offset, gettype($object)));
414 $this->_objects[$offset] = $object;
426 public function offsetUnset($offset)
428 if (!$this->offsetExists($offset))
435 if ($offset == $this->_current)
438 $keys = $this->keys();
439 $position = array_search($this->_current, $keys);
445 $this->_current = $keys[$position - 1];
450 $this->_current =
false;
454 unset($this->_objects[$offset]);
464 public function rewind()
467 if (empty($this->_objects))
469 $this->_current =
false;
473 $keys = $this->keys();
474 $this->_current = array_shift($keys);
485 public function valid()
488 if (!is_scalar($this->_current) || !isset($this->_objects[$this->_current]))
506 private function _initialise(array $input = array())
508 foreach ($input as $key => $object)
510 if (!is_null($object))
512 $this->offsetSet($key, $object);