Documentation

JsonLdSerializer
in package
implements Serializer

Thin wrapper providing RdfInterface\Serializer API for JSON-LD the parser provided by the ml/json-ld library.

Be aware the implementation provided by the ml/json-ld library is not really focused on performance. If you value speed and/or low memory footprint consider using other serialization format.

Tags
author

zozlak

Interfaces, Classes, Traits and Enums

Serializer

Table of Contents

TRANSFORM_COMPACT  = 3
TRANSFORM_EXPAND  = 1
TRANSFORM_FLATTEN  = 2
TRANSFORM_NONE  = 0
$baseUri  : string|null
$context  : mixed
$jsonEncodeFlags  : int
$options  : array<string|int, mixed>
$transform  : int
__construct()  : mixed
serialize()  : string
serializeStream()  : void

Constants

Properties

Methods

__construct()

public __construct([string $baseUri = null ][, int $transform = self::TRANSFORM_NONE ][, int $jsonEncodeFlags = JSON_UNESCAPED_SLASHES ][, mixed $context = null ][, array<string, mixed> $options = [] ]) : mixed
Parameters
$baseUri : string = null
$transform : int = self::TRANSFORM_NONE

transformation to be applied before serializing to string. One of JsonLdSerializer::TRANSFORM_NONE (default), JsonLdSerializer::TRANSFORM_EXPAND, JsonLdSerializer::TRANSFORM_FLATTEN or JsonLdSerializer::TRANSFORM_COMPACT. In case of JsonLdSerializer::TRANSFORM_COMPACT the $context parameter has to be provided.

$jsonEncodeFlags : int = JSON_UNESCAPED_SLASHES

flags to be passed to the json_encode() call serializing output to a string - see https://www.php.net/manual/en/function.json-encode.php .

$context : mixed = null

context to be passed to ML\JsonLD\JsonLD::compact() or ML\JsonLD\JsonLD::flatten() when $transform equals JsonLdSerializer::TRANSFORM_COMPACT or JsonLdSerializer::TRANSFORM_FLATTEN, repectively.

$options : array<string, mixed> = []

options to be passed to the corresponding ML\JsonLD\JsonLD method (expand(), compact() or flatten() according to the $transform parameter value). If you would like these methods to be better documented, then you are not then only one... :-(

Tags
see
JsonLD::expand()
see
JsonLD::flatten()
see
JsonLD::compact()
see
json_encode()
Return values
mixed

serialize()

public serialize(QuadIterator $graph[, RdfNamespace|null $nmsp = null ]) : string
Parameters
$graph : QuadIterator
$nmsp : RdfNamespace|null = null

If passed, it's used for compacting the output. Unfortunately only property URIs can be compacted that way (of course for that full property URIs must be registered as "namespaces").

Tags
throws
RdfIoException
Return values
string

Search results