Documentation

Document
in package
implements DocumentInterface, JsonLdSerializable

A Document represents a JSON-LD document.

Named graphs are not supported yet.

Tags
author

Markus Lanthaler mail@markus-lanthaler.com

Table of Contents

Interfaces

DocumentInterface
JSON-LD document interface
JsonLdSerializable
The JsonLdSerializable interface

Properties

$defaultGraph  : GraphInterface
$iri  : IRI
$namedGraphs  : array<string|int, mixed>

Methods

__construct()  : mixed
Constructor
containsGraph()  : bool
Check whether the document contains a graph with the specified name
createGraph()  : GraphInterface
Creates a new graph which is linked to this document
getGraph()  : GraphInterface|null
Get a graph by name
getGraphNames()  : array<string|int, string>
Get graph names
getIri()  : string|IRI
Get the document's IRI
load()  : Document
Parses a JSON-LD document and returns it as a Document
removeGraph()  : self
Removes a graph from the document
setIri()  : self
Set the document's IRI
toJsonLd()  : mixed
Convert to expanded and flattened JSON-LD

Properties

$iri

protected IRI $iri = null

The document's IRI

$namedGraphs

protected array<string|int, mixed> $namedGraphs = array()

An associative array holding all named graphs in the document

Methods

__construct()

Constructor

public __construct([null|string|IRI $iri = null ]) : mixed
Parameters
$iri : null|string|IRI = null

The document's IRI

containsGraph()

Check whether the document contains a graph with the specified name

public containsGraph(mixed $name) : bool
Parameters
$name : mixed

The graph name.

Return values
bool

Returns true if the document contains a graph with the specified name; false otherwise.

createGraph()

Creates a new graph which is linked to this document

public createGraph(mixed $name) : GraphInterface
Parameters
$name : mixed

The graph's name.

Return values
GraphInterface

The newly created graph.

getGraph()

Get a graph by name

public getGraph([mixed $name = null ]) : GraphInterface|null
Parameters
$name : mixed = null

The name of the graph to retrieve. If null is passed, the default will be returned.

Return values
GraphInterface|null

Returns the graph if found; null otherwise.

getGraphNames()

Get graph names

public getGraphNames() : array<string|int, string>
Return values
array<string|int, string>

Returns the names of all graphs in the document.

getIri()

Get the document's IRI

public getIri([mixed $asObject = false ]) : string|IRI
Parameters
$asObject : mixed = false

If set to true, the return value will be an object; otherwise a string.

Return values
string|IRI

The document's IRI (might be empty).

load()

Parses a JSON-LD document and returns it as a Document

public static load(string|array<string|int, mixed>|stdClass $document[, null|array<string|int, mixed>|stdClass $options = null ]) : Document

The document can be supplied directly as a string or by passing a file path or an IRI.

Usage: $document = Document::load('document.jsonld');

Please note that currently all data is merged into the default graph, named graphs are not supported yet!

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

  • base The base IRI of the input document.
Parameters
$document : string|array<string|int, mixed>|stdClass

The JSON-LD document to process.

$options : null|array<string|int, mixed>|stdClass = null

Options to configure the processing.

Tags
throws
ParseException

If the JSON-LD input document is invalid.

Return values
Document

The parsed JSON-LD document.

removeGraph()

Removes a graph from the document

public removeGraph([mixed $graph = null ]) : self
Parameters
$graph : mixed = null

The graph (or its name) to remove. If null is passed, the default will be reset.

Return values
self

setIri()

Set the document's IRI

public setIri(mixed $iri) : self
Parameters
$iri : mixed
Return values
self

toJsonLd()

Convert to expanded and flattened JSON-LD

public toJsonLd([mixed $useNativeTypes = true ]) : mixed
Parameters
$useNativeTypes : mixed = true

If set to true, native types are used for xsd:integer, xsd:double, and xsd:boolean, otherwise typed strings will be used instead.

Return values
mixed

Returns data which can be serialized by JsonLD::toString() (which is a value of any type other than a resource) to expanded JSON-LD.


        
On this page

Search results