From 63a59e63a8c37173bde195412479a8edf352c275 Mon Sep 17 00:00:00 2001 From: Dave Longley Date: Thu, 28 Mar 2013 12:12:13 -0400 Subject: [PATCH] Fix bug when renaming @type blank nodes when flattening. --- jsonld.php | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/jsonld.php b/jsonld.php index 0bbe371..841ec3c 100644 --- a/jsonld.php +++ b/jsonld.php @@ -1,7 +1,7 @@ {'@type'}; - $types = self::arrayify($types); - foreach($types as $type) { - $id = (strpos($type, '_:') === 0) ? $namer->getName($type) : $type; - if(!property_exists($graphs->{$graph}, $id)) { - $graphs->{$graph}->{$id} = (object)array('@id' => $id); - } - } - } - - // add add values to list + // add values to list if(self::_isValue($input)) { + if(property_exists($input, '@type')) { + $type = $input->{'@type'}; + // rename @type blank node + if(strpos($type, '_:') === 0) { + $type = $input->{'@type'} = $namer->getName($type); + } + if(!property_exists($graphs->{$graph}, $type)) { + $graphs->{$graph}->{$type} = (object)array('@id' => $type); + } + } if($list !== null) { $list[] = $input; } @@ -3283,6 +3281,14 @@ class JsonLdProcessor { continue; } foreach($objects as $o) { + if($property === '@type') { + // rename @type blank nodes + $o = (strpos($o, '_:') === 0) ? $namer->getName($o) : $o; + if(!property_exists($graphs->{$graph}, $o)) { + $graphs->{$graph}->{$o} = (object)array('@id' => $o); + } + } + // handle embedded subject or subject reference if(self::_isSubject($o) || self::_isSubjectReference($o)) { // rename blank node @id