From a4eb8e6d4b3be701fc914770d5d6582de106a13f Mon Sep 17 00:00:00 2001 From: Dave Longley Date: Tue, 9 Apr 2013 11:31:26 -0400 Subject: [PATCH] Always use @graph when context output is an array. --- jsonld.php | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/jsonld.php b/jsonld.php index 1d9d0c2..53b18cc 100644 --- a/jsonld.php +++ b/jsonld.php @@ -1,7 +1,7 @@ _compactIri($active_ctx, '@graph'); - $graph = $compacted; - $compacted = new stdClass(); - 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(); + // add context and/or @graph + if(is_array($compacted)) { + // use '@graph' keyword + $kwgraph = $this->_compactIri($active_ctx, '@graph'); + $graph = $compacted; + $compacted = new stdClass(); + if($has_context) { $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; } }