Updated to pass tests.
This commit is contained in:
parent
210b77ea5e
commit
be88eaa0c4
22
jsonld.php
22
jsonld.php
|
@ -1315,21 +1315,25 @@ function _flatten($parent, $parentProperty, $value, $subjects)
|
||||||
// drop null values
|
// drop null values
|
||||||
if($v !== null)
|
if($v !== null)
|
||||||
{
|
{
|
||||||
if(is_array($v))
|
if(property_exists($subject, $key))
|
||||||
{
|
{
|
||||||
$subject->$key = new ArrayObject();
|
if(!is_array($subject->$key))
|
||||||
_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
|
$subject->$key = new ArrayObject(array($subject->$key));
|
||||||
$arr = $subject->$key;
|
|
||||||
$subject->$key = $arr[0];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
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];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue