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

View file

@ -1,7 +1,7 @@
<?php
/**
* PHP implementation of the JSON-LD API.
* Version: 0.0.26
* Version: 0.0.27
*
* @author Dave Longley
*
@ -697,8 +697,7 @@ class JsonLdProcessor {
$ctx = $ctx[0];
}
// add context
if($has_context || $options['graph']) {
// add context and/or @graph
if(is_array($compacted)) {
// use '@graph' keyword
$kwgraph = $this->_compactIri($active_ctx, '@graph');
@ -709,7 +708,7 @@ class JsonLdProcessor {
}
$compacted->{$kwgraph} = $graph;
}
else if(is_object($compacted)) {
else if(is_object($compacted) && $has_context) {
// reorder keys so @context is first
$graph = $compacted;
$compacted = new stdClass();
@ -718,7 +717,6 @@ class JsonLdProcessor {
$compacted->{$k} = $v;
}
}
}
if($options['activeCtx']) {
return array('compacted' => $compacted, 'activeCtx' => $active_ctx);