Updated to pass tests.

This commit is contained in:
Dave Longley 2011-08-06 23:24:17 -04:00
parent 210b77ea5e
commit be88eaa0c4

View file

@ -1315,21 +1315,25 @@ function _flatten($parent, $parentProperty, $value, $subjects)
// drop null values
if($v !== null)
{
if(is_array($v))
if(property_exists($subject, $key))
{
$subject->$key = new ArrayObject();
_flatten($subject->$key, null, $value->$key, $subjects);
$subject->$key = (array)$subject->$key;
if(count($subject->$key) === 1)
if(!is_array($subject->$key))
{
// convert subject[key] to object if it has only 1
$arr = $subject->$key;
$subject->$key = $arr[0];
$subject->$key = new ArrayObject(array($subject->$key));
}
}
else
{
_flatten($subject, $key, $value->$key, $subjects);
$subject->$key = new ArrayObject();
}
_flatten($subject->$key, null, $value->$key, $subjects);
$subject->$key = (array)$subject->$key;
if(count($subject->$key) === 1)
{
// convert subject[key] to object if it has only 1
$arr = $subject->$key;
$subject->$key = $arr[0];
}
}
}