Removed nulls in flatten.

This commit is contained in:
Dave Longley 2011-07-29 11:46:23 -04:00
parent d841bf535c
commit 4d7d0fa0ae

View file

@ -856,9 +856,14 @@ function _expand($ctx, $property, $value, $expandSubjects)
// TODO: add data format error detection? // TODO: add data format error detection?
// value is null, nothing to expand
if($value === null)
{
$rval = null;
}
// if no property is specified and the value is a string (this means the // if no property is specified and the value is a string (this means the
// value is a property itself), expand to an IRI // value is a property itself), expand to an IRI
if($property === null and is_string($value)) else if($property === null and is_string($value))
{ {
$rval = _expandTerm($ctx, $value, null); $rval = _expandTerm($ctx, $value, null);
} }
@ -1224,7 +1229,11 @@ class NameGenerator
*/ */
function _collectSubjects($input, $subjects, $bnodes) function _collectSubjects($input, $subjects, $bnodes)
{ {
if(is_array($input)) if($input === null)
{
// nothing to collect
}
else if(is_array($input))
{ {
foreach($input as $value) foreach($input as $value)
{ {
@ -1344,21 +1353,25 @@ function _flatten($parent, $parentProperty, $value, $subjects)
// flatten embeds // flatten embeds
foreach($value as $key => $v) foreach($value as $key => $v)
{ {
if(is_array($v)) // drop null values
if($v !== null)
{ {
$subject->$key = new ArrayObject(); if(is_array($v))
_flatten($subject->$key, null, $value->$key, $subjects);
$subject->$key = (array)$subject->$key;
if(count($subject->$key) === 1)
{ {
// convert subject[key] to object if only 1 value was added $subject->$key = new ArrayObject();
$arr = $subject->$key; _flatten($subject->$key, null, $value->$key, $subjects);
$subject->$key = $arr[0]; $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];
}
}
else
{
_flatten($subject, $key, $value->$key, $subjects);
} }
}
else
{
_flatten($subject, $key, $value->$key, $subjects);
} }
} }
} }