forked from friendica/php-json-ld
Add @base support.
This commit is contained in:
parent
eb3c8ba42d
commit
cb03711585
1 changed files with 25 additions and 1 deletions
26
jsonld.php
26
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.7
|
* Version: 0.0.8
|
||||||
*
|
*
|
||||||
* @author Dave Longley
|
* @author Dave Longley
|
||||||
*
|
*
|
||||||
|
@ -2626,6 +2626,30 @@ class JsonLdProcessor {
|
||||||
// define context mappings for keys in local context
|
// define context mappings for keys in local context
|
||||||
$defined = new stdClass();
|
$defined = new stdClass();
|
||||||
|
|
||||||
|
// handle @base
|
||||||
|
if(property_exists($ctx, '@base')) {
|
||||||
|
$base = $ctx->{'@base'};
|
||||||
|
if($base === null) {
|
||||||
|
$rval->{'@base'} = jsonld_parse_url($options['base']);
|
||||||
|
}
|
||||||
|
else if(!is_string($base)) {
|
||||||
|
throw new JsonLdException(
|
||||||
|
'Invalid JSON-LD syntax; the value of "@base" in a ' .
|
||||||
|
'@context must be a string or null.',
|
||||||
|
'jsonld.SyntaxError', array('context' => $ctx));
|
||||||
|
}
|
||||||
|
else if(!self::_isAbsoluteIri($base)) {
|
||||||
|
throw new JsonLdException(
|
||||||
|
'Invalid JSON-LD syntax; the value of "@base" in a ' .
|
||||||
|
'@context must be an absolute IRI.',
|
||||||
|
'jsonld.SyntaxError', array('context' => $ctx));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$rval->{'@base'} = $base;
|
||||||
|
}
|
||||||
|
$defined->{'@base'} = true;
|
||||||
|
}
|
||||||
|
|
||||||
// handle @vocab
|
// handle @vocab
|
||||||
if(property_exists($ctx, '@vocab')) {
|
if(property_exists($ctx, '@vocab')) {
|
||||||
$value = $ctx->{'@vocab'};
|
$value = $ctx->{'@vocab'};
|
||||||
|
|
Loading…
Add table
Reference in a new issue