forked from friendica/php-json-ld
Fix bug when renaming @type blank nodes when flattening.
This commit is contained in:
parent
b3d8b564d0
commit
63a59e63a8
34
jsonld.php
34
jsonld.php
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* PHP implementation of the JSON-LD API.
|
* PHP implementation of the JSON-LD API.
|
||||||
* Version: 0.0.18
|
* Version: 0.0.19
|
||||||
*
|
*
|
||||||
* @author Dave Longley
|
* @author Dave Longley
|
||||||
*
|
*
|
||||||
|
@ -3182,20 +3182,18 @@ class JsonLdProcessor {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// add entries for @type
|
// add values to list
|
||||||
if(property_exists($input, '@type')) {
|
|
||||||
$types = $input->{'@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
|
|
||||||
if(self::_isValue($input)) {
|
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) {
|
if($list !== null) {
|
||||||
$list[] = $input;
|
$list[] = $input;
|
||||||
}
|
}
|
||||||
|
@ -3283,6 +3281,14 @@ class JsonLdProcessor {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
foreach($objects as $o) {
|
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
|
// handle embedded subject or subject reference
|
||||||
if(self::_isSubject($o) || self::_isSubjectReference($o)) {
|
if(self::_isSubject($o) || self::_isSubjectReference($o)) {
|
||||||
// rename blank node @id
|
// rename blank node @id
|
||||||
|
|
Loading…
Reference in a new issue