public function getQueryArray($uriParameterName = null, $member = true)
{
if (func_num_args() > 2) {
$known = func_get_arg(2);
}
if (!isset($known)) {
$known = array();
}
$id = spl_object_hash($this);
if (array_key_exists($id, $known)) {
return '**recursion**';
}
$known[$id] = true;
$prefix = $uriParameterName !== null ? $uriParameterName . '.' : '';
$fnCast = function ($value) {
return $value instanceof StringType ? (string) $value : $value;
};
$n = 1;
$arr = array();
$trait = function ($key, $val) use(&$known, $prefix, $member) {
if (is_object($val) || is_array($val)) {
if ($val instanceof AbstractDataType) {
$val = $val->getQueryArray(ucfirst($key), $member, $known);
} else {
if ($val instanceof \DateTime) {
$val = $val->format('c');
} else {
if ($val instanceof StringType) {
$val = (string) $val;
} else {
$val = (array) $val;
$bCastType = true;
}
}
}
if (($prefix != '' || isset($bCastType)) && !empty($val) && is_array($val)) {
$i = 1;
$val = array_combine(array_map(function ($k) use($prefix, $key, $member, &$i) {
return (empty($prefix) ? ucfirst($key) . ($member ? '.member.' : '.') : $prefix) . (is_numeric($k) ? $i++ : ucfirst($k));
}, array_keys($val)), array_values($val));
}
} else {
if (is_int($val) || is_float($val)) {
$val = (string) $val;
} else {
if (is_bool($val)) {
$val = $val ? 'true' : 'false';
}
}
}
return $val;
};
$props = $this->getReflectionClass()->getProperties(\ReflectionProperty::IS_PUBLIC);
/* @var $prop \ReflectionProperty */
foreach ($props as $prop) {
$val = $trait($prop->getName(), $prop->getValue($this));
if ($val === null) {
continue;
}
if (is_array($val)) {
$arr = array_merge($arr, $val);
} else {
$arr[$prefix . $this->uppercaseProperty($prop->getName())] = $val;
}
}
//Passes through an internal properties as well
foreach ($this->_properties as $prop) {
if (isset($this->propertiesData[$prop])) {
$val = $trait($prop, $this->propertiesData[$prop]);
} else {
$val = null;
continue;
}
if (is_array($val)) {
$arr = array_merge($arr, $val);
} else {
$arr[$prefix . $this->uppercaseProperty($prop)] = $val;
}
}
return array_filter($arr, function ($v) {
return $v !== null;
});
}