forked from friendica/php-json-ld
Some code clean up/reorganization.
This commit is contained in:
parent
265689c92f
commit
ae46860dab
24
jsonld.php
24
jsonld.php
|
@ -208,7 +208,7 @@ class JsonLdProcessor {
|
||||||
// remove empty contexts
|
// remove empty contexts
|
||||||
$tmp = $ctx;
|
$tmp = $ctx;
|
||||||
$ctx = array();
|
$ctx = array();
|
||||||
foreach($tmp as $i => $v) {
|
foreach($tmp as $v) {
|
||||||
if(!is_object($v) || count(get_object_vars($v)) > 0) {
|
if(!is_object($v) || count(get_object_vars($v)) > 0) {
|
||||||
$ctx[] = $v;
|
$ctx[] = $v;
|
||||||
}
|
}
|
||||||
|
@ -436,7 +436,7 @@ class JsonLdProcessor {
|
||||||
// FIXME: implement jsonld_resolve_url
|
// FIXME: implement jsonld_resolve_url
|
||||||
isset($options['resolver']) or $options['resolver'] = 'jsonld_resolve_url';
|
isset($options['resolver']) or $options['resolver'] = 'jsonld_resolve_url';
|
||||||
|
|
||||||
// resolve URLs in localCtx
|
// resolve URLs in local_ctx
|
||||||
$local_ctx = self::copy($local_ctx);
|
$local_ctx = self::copy($local_ctx);
|
||||||
if(is_object($local_ctx) && !property_exists($local_ctx, '@context')) {
|
if(is_object($local_ctx) && !property_exists($local_ctx, '@context')) {
|
||||||
$local_ctx = (object)array('@context' => $local_ctx);
|
$local_ctx = (object)array('@context' => $local_ctx);
|
||||||
|
@ -744,13 +744,10 @@ class JsonLdProcessor {
|
||||||
*
|
*
|
||||||
* @param mixed $value the value.
|
* @param mixed $value the value.
|
||||||
*
|
*
|
||||||
* @return an array.
|
* @return array an array.
|
||||||
*/
|
*/
|
||||||
public static function arrayify($value) {
|
public static function arrayify($value) {
|
||||||
if(is_array($value)) {
|
return is_array($value) ? $value : array($value);
|
||||||
return $value;
|
|
||||||
}
|
|
||||||
return array($value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -967,8 +964,13 @@ class JsonLdProcessor {
|
||||||
return $rval;
|
return $rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
// recursively expand object
|
// expand non-object element according to value expansion rules
|
||||||
if(is_object($element)) {
|
if(!is_object($element)) {
|
||||||
|
return $this->_expandValue($ctx, $property, $element, $options['base']);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Note: element must be an object, recursively expand it
|
||||||
|
|
||||||
// if element has a context, process it
|
// if element has a context, process it
|
||||||
if(property_exists($element, '@context')) {
|
if(property_exists($element, '@context')) {
|
||||||
$ctx = $this->_processContext($ctx, $element->{'@context'}, $options);
|
$ctx = $this->_processContext($ctx, $element->{'@context'}, $options);
|
||||||
|
@ -1120,10 +1122,6 @@ class JsonLdProcessor {
|
||||||
return $rval;
|
return $rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
// expand element according to value expansion rules
|
|
||||||
return $this->_expandValue($ctx, $property, $element, $options['base']);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs JSON-LD framing.
|
* Performs JSON-LD framing.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue