/** * Flatten a JSON-LD document * * Both the document and the context can be supplied directly as string, * by passing a file path, or by passing a URL. * * Usage: * * $flattened = JsonLD::flatten('document.jsonld'); * print_r($flattened); * * It is possible to configure the flattening 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>graph</dt> * <dd>The graph whose flattened representation should be returned. * The default graph is identified by {@link DEFAULT_GRAPH} and the * merged dataset graph by {@link MERGED_GRAPH}. If <em>null</em> is * passed, all graphs will be returned.</dd> * </dl> * * The options parameter might be passed as associative array or as * object. * * @param string|object|array $input The JSON-LD document to flatten. * @param null|string|object|array $context The context to compact the * flattened document. If * <em>null</em> is passed, the * result will not be compacted. * @param null|array|object $options Options to configure the * flattening process. * * @return object The flattened JSON-LD document. * * @throws JsonLdException * * @api */ public static function flatten($input, $context = null, $options = null) { $options = self::mergeOptions($options); $input = self::expand($input, $options); $processor = new Processor($options); $flattened = $processor->flatten($input, $options->graph); if (null === $context) { return $flattened; } return self::doCompact($flattened, $context, $options, true); }