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,9 +1315,18 @@ function _flatten($parent, $parentProperty, $value, $subjects)
// drop null values
if($v !== null)
{
if(is_array($v))
if(property_exists($subject, $key))
{
if(!is_array($subject->$key))
{
$subject->$key = new ArrayObject(array($subject->$key));
}
}
else
{
$subject->$key = new ArrayObject();
}
_flatten($subject->$key, null, $value->$key, $subjects);
$subject->$key = (array)$subject->$key;
if(count($subject->$key) === 1)
@ -1327,11 +1336,6 @@ function _flatten($parent, $parentProperty, $value, $subjects)
$subject->$key = $arr[0];
}
}
else
{
_flatten($subject, $key, $value->$key, $subjects);
}
}
}
}
}