forked from friendica/php-json-ld
Always use @graph when context output is an array.
This commit is contained in:
parent
f5337b8118
commit
a4eb8e6d4b
38
jsonld.php
38
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.26
|
* Version: 0.0.27
|
||||||
*
|
*
|
||||||
* @author Dave Longley
|
* @author Dave Longley
|
||||||
*
|
*
|
||||||
|
@ -697,26 +697,24 @@ class JsonLdProcessor {
|
||||||
$ctx = $ctx[0];
|
$ctx = $ctx[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
// add context
|
// add context and/or @graph
|
||||||
if($has_context || $options['graph']) {
|
if(is_array($compacted)) {
|
||||||
if(is_array($compacted)) {
|
// use '@graph' keyword
|
||||||
// use '@graph' keyword
|
$kwgraph = $this->_compactIri($active_ctx, '@graph');
|
||||||
$kwgraph = $this->_compactIri($active_ctx, '@graph');
|
$graph = $compacted;
|
||||||
$graph = $compacted;
|
$compacted = new stdClass();
|
||||||
$compacted = new stdClass();
|
if($has_context) {
|
||||||
if($has_context) {
|
|
||||||
$compacted->{'@context'} = $ctx;
|
|
||||||
}
|
|
||||||
$compacted->{$kwgraph} = $graph;
|
|
||||||
}
|
|
||||||
else if(is_object($compacted)) {
|
|
||||||
// reorder keys so @context is first
|
|
||||||
$graph = $compacted;
|
|
||||||
$compacted = new stdClass();
|
|
||||||
$compacted->{'@context'} = $ctx;
|
$compacted->{'@context'} = $ctx;
|
||||||
foreach($graph as $k => $v) {
|
}
|
||||||
$compacted->{$k} = $v;
|
$compacted->{$kwgraph} = $graph;
|
||||||
}
|
}
|
||||||
|
else if(is_object($compacted) && $has_context) {
|
||||||
|
// reorder keys so @context is first
|
||||||
|
$graph = $compacted;
|
||||||
|
$compacted = new stdClass();
|
||||||
|
$compacted->{'@context'} = $ctx;
|
||||||
|
foreach($graph as $k => $v) {
|
||||||
|
$compacted->{$k} = $v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue