forked from friendica/php-json-ld
Fix context caching bug.
- Update active context for each processed context to ensure the proper associations are made in the cache between an active context, the local context processed, and the result.
This commit is contained in:
parent
cbefb2d662
commit
89d90fbae2
19
jsonld.php
19
jsonld.php
|
@ -2982,14 +2982,13 @@ class JsonLdProcessor {
|
||||||
return self::_cloneActiveContext($active_ctx);
|
return self::_cloneActiveContext($active_ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
// process each context in order
|
// process each context in order, update active context
|
||||||
|
// on each iteration to ensure proper caching
|
||||||
$rval = $active_ctx;
|
$rval = $active_ctx;
|
||||||
$must_clone = true;
|
|
||||||
foreach($ctxs as $ctx) {
|
foreach($ctxs as $ctx) {
|
||||||
// reset to initial context
|
// reset to initial context
|
||||||
if($ctx === null) {
|
if($ctx === null) {
|
||||||
$rval = $this->_getInitialContext($options);
|
$rval = $active_ctx = $this->_getInitialContext($options);
|
||||||
$must_clone = false;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3010,17 +3009,15 @@ class JsonLdProcessor {
|
||||||
if(property_exists($jsonld_cache, 'activeCtx')) {
|
if(property_exists($jsonld_cache, 'activeCtx')) {
|
||||||
$cached = $jsonld_cache->activeCtx->get($active_ctx, $ctx);
|
$cached = $jsonld_cache->activeCtx->get($active_ctx, $ctx);
|
||||||
if($cached) {
|
if($cached) {
|
||||||
$rval = $cached;
|
$rval = $active_ctx = $cached;
|
||||||
$must_clone = true;
|
$must_clone = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// clone context, if required, before updating
|
// update active context and clone new one before updating
|
||||||
if($must_clone) {
|
$active_ctx = $rval;
|
||||||
$rval = self::_cloneActiveContext($rval);
|
$rval = self::_cloneActiveContext($rval);
|
||||||
$must_clone = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// define context mappings for keys in local context
|
// define context mappings for keys in local context
|
||||||
$defined = new stdClass();
|
$defined = new stdClass();
|
||||||
|
@ -4698,7 +4695,7 @@ class JsonLdProcessor {
|
||||||
throw new JsonLdException(
|
throw new JsonLdException(
|
||||||
'Invalid JSON-LD syntax; keywords cannot be overridden.',
|
'Invalid JSON-LD syntax; keywords cannot be overridden.',
|
||||||
'jsonld.SyntaxError', 'keyword redefinition',
|
'jsonld.SyntaxError', 'keyword redefinition',
|
||||||
array('context' => $local_ctx));
|
array('context' => $local_ctx, 'term' => $term));
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove old mapping
|
// remove old mapping
|
||||||
|
|
Loading…
Reference in a new issue