public function toArray($ucase = false, &$known = null)
{
$arr = array();
if (is_null($known)) {
$known = array();
}
$id = spl_object_hash($this);
if (array_key_exists($id, $known)) {
return '**recursion**';
}
$known[$id] = true;
$trait = function (&$val) use($ucase, &$known) {
if (is_object($val)) {
if ($val instanceof AbstractDataType) {
$val = $val->toArray($ucase, $known);
} else {
$val = (array) $val;
}
}
};
if ($this instanceof ListDataType) {
foreach ($this->getOriginal() as $val) {
$trait($val);
$arr[] = $val;
}
} else {
$props = $this->getReflectionClass()->getProperties(\ReflectionProperty::IS_PUBLIC);
/* @var $prop \ReflectionProperty */
foreach ($props as $prop) {
$val = $prop->getValue($this);
$trait($val);
$arr[$ucase ? ucfirst($prop->getName()) : $prop->getName()] = $val;
}
//Passes through an internal properties as well
foreach ($this->_properties as $prop) {
if (isset($this->propertiesData[$prop])) {
$val = $this->propertiesData[$prop];
$trait($val);
} else {
$val = null;
}
$arr[$ucase ? ucfirst($prop) : $prop] = $val;
}
}
return $arr;
}