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?
// 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
// 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);
}
@ -1224,7 +1229,11 @@ class NameGenerator
*/
function _collectSubjects($input, $subjects, $bnodes)
{
if(is_array($input))
if($input === null)
{
// nothing to collect
}
else if(is_array($input))
{
foreach($input as $value)
{
@ -1343,6 +1352,9 @@ function _flatten($parent, $parentProperty, $value, $subjects)
// flatten embeds
foreach($value as $key => $v)
{
// drop null values
if($v !== null)
{
if(is_array($v))
{
@ -1351,7 +1363,7 @@ function _flatten($parent, $parentProperty, $value, $subjects)
$subject->$key = (array)$subject->$key;
if(count($subject->$key) === 1)
{
// convert subject[key] to object if only 1 value was added
// convert subject[key] to object if it has only 1
$arr = $subject->$key;
$subject->$key = $arr[0];
}
@ -1363,6 +1375,7 @@ function _flatten($parent, $parentProperty, $value, $subjects)
}
}
}
}
// string value
else
{