Add @base support.

This commit is contained in:
Dave Longley 2013-02-28 16:03:11 -05:00
parent eb3c8ba42d
commit cb03711585
1 changed files with 25 additions and 1 deletions

View File

@ -1,7 +1,7 @@
<?php
/**
* PHP implementation of the JSON-LD API.
* Version: 0.0.7
* Version: 0.0.8
*
* @author Dave Longley
*
@ -2626,6 +2626,30 @@ class JsonLdProcessor {
// define context mappings for keys in local context
$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
if(property_exists($ctx, '@vocab')) {
$value = $ctx->{'@vocab'};