forked from friendica/php-json-ld
Fix bug when renaming @type blank nodes when flattening.
This commit is contained in:
parent
b3d8b564d0
commit
63a59e63a8
32
jsonld.php
32
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')) {
|
if(self::_isValue($input)) {
|
||||||
$types = $input->{'@type'};
|
if(property_exists($input, '@type')) {
|
||||||
$types = self::arrayify($types);
|
$type = $input->{'@type'};
|
||||||
foreach($types as $type) {
|
// rename @type blank node
|
||||||
$id = (strpos($type, '_:') === 0) ? $namer->getName($type) : $type;
|
if(strpos($type, '_:') === 0) {
|
||||||
if(!property_exists($graphs->{$graph}, $id)) {
|
$type = $input->{'@type'} = $namer->getName($type);
|
||||||
$graphs->{$graph}->{$id} = (object)array('@id' => $id);
|
}
|
||||||
|
if(!property_exists($graphs->{$graph}, $type)) {
|
||||||
|
$graphs->{$graph}->{$type} = (object)array('@id' => $type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// add add values to list
|
|
||||||
if(self::_isValue($input)) {
|
|
||||||
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