10 defined(
'JPATH_PLATFORM') or die;
28 private $_properties = array();
39 public function __construct($properties = array())
42 if (!empty($properties))
45 $this->bind($properties);
66 public function __get($property)
68 return $this->getProperty($property);
80 public function __isset($property)
82 return isset($this->_properties[$property]);
98 public function __set($property, $value)
100 $this->setProperty($property, $value);
112 public function __unset($property)
114 unset($this->_properties[$property]);
128 public function bind($properties, $updateNulls =
true)
131 if (!is_array($properties) && !is_object($properties))
133 throw new InvalidArgumentException(sprintf(
'%s(%s)', __METHOD__, gettype($properties)));
137 if ($properties instanceof Traversable)
140 $properties = iterator_to_array($properties);
143 elseif (is_object($properties))
146 $properties = (array) $properties;
150 foreach ($properties as $property => $value)
153 if ($value === null && !$updateNulls)
159 $this->setProperty($property, $value);
177 public function dump($depth = 3, SplObjectStorage $dumped = null)
180 if ($dumped === null)
182 $dumped =
new SplObjectStorage;
186 $dumped->attach($this);
189 $dump =
new stdClass;
192 foreach (array_keys($this->_properties) as $property)
195 $dump->$property = $this->dumpProperty($property, $depth, $dumped);
211 public function getIterator()
213 return new ArrayIterator($this->dump(0));
223 public function jsonSerialize()
225 return $this->dump();
242 protected function dumpProperty($property, $depth, SplObjectStorage $dumped)
244 $value = $this->getProperty($property);
249 if ($value instanceof JDataDumpable)
252 if (!$dumped->contains($value))
254 $value = $value->dump($depth - 1, $dumped);
259 if ($value instanceof
JDate)
261 $value = (string) $value;
266 $value = $value->toObject();
283 protected function getProperty($property)
286 $value = array_key_exists($property, $this->_properties) ? $this->_properties[$property] : null;
304 protected function setProperty($property, $value)
310 if (strpos($property,
"\0") === 0)
316 $this->_properties[$property] = $value;
328 public function count()
330 return count($this->_properties);