Always use @graph when context output is an array.

This commit is contained in:
Dave Longley 2013-04-09 11:31:26 -04:00
parent f5337b8118
commit a4eb8e6d4b
1 changed files with 18 additions and 20 deletions

View File

@ -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,8 +697,7 @@ 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');
@ -709,7 +708,7 @@ class JsonLdProcessor {
} }
$compacted->{$kwgraph} = $graph; $compacted->{$kwgraph} = $graph;
} }
else if(is_object($compacted)) { else if(is_object($compacted) && $has_context) {
// reorder keys so @context is first // reorder keys so @context is first
$graph = $compacted; $graph = $compacted;
$compacted = new stdClass(); $compacted = new stdClass();
@ -718,7 +717,6 @@ class JsonLdProcessor {
$compacted->{$k} = $v; $compacted->{$k} = $v;
} }
} }
}
if($options['activeCtx']) { if($options['activeCtx']) {
return array('compacted' => $compacted, 'activeCtx' => $active_ctx); return array('compacted' => $compacted, 'activeCtx' => $active_ctx);