forked from friendica/php-json-ld
Skip IRI processing when base is null.
This commit is contained in:
parent
75f919fa79
commit
7791361f1f
35
jsonld.php
35
jsonld.php
|
@ -586,6 +586,11 @@ function jsonld_remove_dot_segments($path, $has_authority) {
|
||||||
* @return string the absolute IRI.
|
* @return string the absolute IRI.
|
||||||
*/
|
*/
|
||||||
function jsonld_prepend_base($base, $iri) {
|
function jsonld_prepend_base($base, $iri) {
|
||||||
|
// skip IRI processing
|
||||||
|
if($base === null) {
|
||||||
|
return $iri;
|
||||||
|
}
|
||||||
|
|
||||||
// already an absolute IRI
|
// already an absolute IRI
|
||||||
if(strpos($iri, ':') !== false) {
|
if(strpos($iri, ':') !== false) {
|
||||||
return $iri;
|
return $iri;
|
||||||
|
@ -659,6 +664,11 @@ function jsonld_prepend_base($base, $iri) {
|
||||||
* IRI.
|
* IRI.
|
||||||
*/
|
*/
|
||||||
function jsonld_remove_base($base, $iri) {
|
function jsonld_remove_base($base, $iri) {
|
||||||
|
// skip IRI processing
|
||||||
|
if($base === null) {
|
||||||
|
return $iri;
|
||||||
|
}
|
||||||
|
|
||||||
if(is_string($base)) {
|
if(is_string($base)) {
|
||||||
$base = jsonld_parse_url($base);
|
$base = jsonld_parse_url($base);
|
||||||
}
|
}
|
||||||
|
@ -3069,7 +3079,10 @@ class JsonLdProcessor {
|
||||||
'@context must be an absolute IRI or the empty string.',
|
'@context must be an absolute IRI or the empty string.',
|
||||||
'jsonld.SyntaxError', 'invalid base IRI', array('context' => $ctx));
|
'jsonld.SyntaxError', 'invalid base IRI', array('context' => $ctx));
|
||||||
}
|
}
|
||||||
$rval->{'@base'} = jsonld_parse_url($base);
|
if($base !== null) {
|
||||||
|
$base = jsonld_parse_url($base);
|
||||||
|
}
|
||||||
|
$rval->{'@base'} = $base;
|
||||||
$defined->{'@base'} = true;
|
$defined->{'@base'} = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3285,6 +3298,9 @@ class JsonLdProcessor {
|
||||||
sort($ids);
|
sort($ids);
|
||||||
foreach($ids as $id) {
|
foreach($ids as $id) {
|
||||||
$node = $graph->{$id};
|
$node = $graph->{$id};
|
||||||
|
if($id === '"') {
|
||||||
|
$id = '';
|
||||||
|
}
|
||||||
$properties = array_keys((array)$node);
|
$properties = array_keys((array)$node);
|
||||||
sort($properties);
|
sort($properties);
|
||||||
foreach($properties as $property) {
|
foreach($properties as $property) {
|
||||||
|
@ -3576,9 +3592,19 @@ class JsonLdProcessor {
|
||||||
}
|
}
|
||||||
$subjects = $graphs->{$graph};
|
$subjects = $graphs->{$graph};
|
||||||
if(!property_exists($subjects, $name)) {
|
if(!property_exists($subjects, $name)) {
|
||||||
$subjects->{$name} = new stdClass();
|
if($name === '') {
|
||||||
|
$subjects->{'"'} = new stdClass();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$subjects->{$name} = new stdClass();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if($name === '') {
|
||||||
|
$subject = $subjects->{'"'};
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$subject = $subjects->{$name};
|
||||||
}
|
}
|
||||||
$subject = $subjects->{$name};
|
|
||||||
$subject->{'@id'} = $name;
|
$subject->{'@id'} = $name;
|
||||||
$properties = array_keys((array)$input);
|
$properties = array_keys((array)$input);
|
||||||
sort($properties);
|
sort($properties);
|
||||||
|
@ -3602,6 +3628,9 @@ class JsonLdProcessor {
|
||||||
$item_name = $namer->getName($item_name);
|
$item_name = $namer->getName($item_name);
|
||||||
}
|
}
|
||||||
$this->_createNodeMap($item, $graphs, $graph, $namer, $item_name);
|
$this->_createNodeMap($item, $graphs, $graph, $namer, $item_name);
|
||||||
|
if($item_name === '') {
|
||||||
|
$item_name = '"';
|
||||||
|
}
|
||||||
self::addValue(
|
self::addValue(
|
||||||
$subjects->{$item_name}, $reverse_property, $referenced_node,
|
$subjects->{$item_name}, $reverse_property, $referenced_node,
|
||||||
array('propertyIsArray' => true, 'allowDuplicate' => false));
|
array('propertyIsArray' => true, 'allowDuplicate' => false));
|
||||||
|
|
Loading…
Reference in a new issue