Some code clean up/reorganization.

This commit is contained in:
Dave Longley 2012-04-24 20:29:40 -04:00
parent 265689c92f
commit ae46860dab

View file

@ -208,7 +208,7 @@ class JsonLdProcessor {
// remove empty contexts
$tmp = $ctx;
$ctx = array();
foreach($tmp as $i => $v) {
foreach($tmp as $v) {
if(!is_object($v) || count(get_object_vars($v)) > 0) {
$ctx[] = $v;
}
@ -436,7 +436,7 @@ class JsonLdProcessor {
// FIXME: implement 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);
if(is_object($local_ctx) && !property_exists($local_ctx, '@context')) {
$local_ctx = (object)array('@context' => $local_ctx);
@ -744,13 +744,10 @@ class JsonLdProcessor {
*
* @param mixed $value the value.
*
* @return an array.
* @return array an array.
*/
public static function arrayify($value) {
if(is_array($value)) {
return $value;
}
return array($value);
return is_array($value) ? $value : array($value);
}
/**
@ -967,8 +964,13 @@ class JsonLdProcessor {
return $rval;
}
// recursively expand object
if(is_object($element)) {
// expand non-object element according to value expansion rules
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(property_exists($element, '@context')) {
$ctx = $this->_processContext($ctx, $element->{'@context'}, $options);
@ -1120,10 +1122,6 @@ class JsonLdProcessor {
return $rval;
}
// expand element according to value expansion rules
return $this->_expandValue($ctx, $property, $element, $options['base']);
}
/**
* Performs JSON-LD framing.
*