public static function expand($input, $options = null)
    {
        $options = self::mergeOptions($options);

        $processor = new Processor($options);
        $activectx = array('@base' => null);

        if (is_string($input)) {
            $remoteDocument = $options->documentLoader->loadDocument($input);

            $input = $remoteDocument->document;
            $activectx['@base'] = new IRI($remoteDocument->documentUrl);

            if (null !== $remoteDocument->contextUrl) {
                $processor->processContext($remoteDocument->contextUrl, $activectx);
            }
        }

        if ($options->base) {
            $activectx['@base'] = $options->base;
        }

        if (null !== $options->expandContext) {
            $processor->processContext($options->expandContext, $activectx);
        }

        $processor->expand($input, $activectx);

        // optimize away default graph (@graph as the only property at the top-level object)
        if (is_object($input) && property_exists($input, '@graph') && (1 === count(get_object_vars($input)))) {
            $input = $input->{'@graph'};
        }

        if (false === is_array($input)) {
            $input = (null === $input) ? array() : array($input);
        }

        return $input;
    }
public static function expand($input, $options = null)
    {
        $options = self::mergeOptions($options);

        $processor = new Processor($options);
        $activectx = array('@base' => null);

        if (is_string($input)) {
            $remoteDocument = $options->documentLoader->loadDocument($input);

            $input = $remoteDocument->document;
            $activectx['@base'] = new IRI($remoteDocument->documentUrl);

            if (null !== $remoteDocument->contextUrl) {
                $processor->processContext($remoteDocument->contextUrl, $activectx);
            }
        }

        if ($options->base) {
            $activectx['@base'] = $options->base;
        }

        if (null !== $options->expandContext) {
            $processor->processContext($options->expandContext, $activectx);
        }

        $processor->expand($input, $activectx);

        // optimize away default graph (@graph as the only property at the top-level object)
        if (is_object($input) && property_exists($input, '@graph') && (1 === count(get_object_vars($input)))) {
            $input = $input->{'@graph'};
        }

        if (false === is_array($input)) {
            $input = (null === $input) ? array() : array($input);
        }

        return $input;
    }
public static function expand ( $ input , $ options = null ) { $ options = self :: mergeOptions ( $ options ) ; $ processor = new Processor ( $ options ) ; $ activectx = array ( '@base' => null ) ; if ( is_string ( $ input ) ) { $ remoteDocument = $ options -> documentLoader -> loadDocument ( $ input ) ; $ input = $ remoteDocument -> document ; $ activectx [ '@base' ] = new IRI ( $ remoteDocument -> documentUrl ) ; if ( null !== $ remoteDocument -> contextUrl ) { $ processor -> processContext ( $ remoteDocument -> contextUrl , $ activectx ) ; } } if ( $ options -> base ) { $ activectx [ '@base' ] = $ options -> base ; } if ( null !== $ options -> expandContext ) { $ processor -> processContext ( $ options -> expandContext , $ activectx ) ; } $ processor -> expand ( $ input , $ activectx ) ; // optimize away default graph (@graph as the only property at the top-level object) if ( is_object ( $ input ) && property_exists ( $ input , '@graph' ) && ( 1 === count ( get_object_vars ( $ input ) ) ) ) { $ input = $ input -> { '@graph' } ; } if ( false === is_array ( $ input ) ) { $ input = ( null === $ input ) ? array ( ) : array ( $ input ) ; } return $ input ; }
Expand a JSON-LD document

The document can be supplied directly as string, by passing a file
path, or by passing a URL.

Usage:

$expanded = JsonLD::expand('document.jsonld');
print_r($expanded);

It is possible to configure the expansion process by setting the options
parameter accordingly. Available options are:

<dl>
<dt>base</dt>
<dd>The base IRI of the input document.</dd>

<dt>expandContext</dt>
<dd>An optional context to use additionally to the context embedded
in input when expanding the input.</dd>

<dt>documentLoader</dt>
<dd>The document loader.</dd>
</dl>

The options parameter might be passed as associative array or as
object.

@param string|JsonObject|array $input   The JSON-LD document to expand.
@param null|array|JsonObject   $options Options to configure the expansion
process.

@return array The expanded JSON-LD document.

@throws JsonLdException

@api
Expand a JSON - LD document