Documentation

JsonLdSerializer
in package
implements SerializerInterface

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

Table of Contents

Interfaces

SerializerInterface

Constants

TRANSFORM_COMPACT  = 3
TRANSFORM_EXPAND  = 1
TRANSFORM_FLATTEN  = 2
TRANSFORM_NONE  = 0

Properties

$baseUri  : string|null
$context  : mixed
$jsonEncodeFlags  : int
$options  : array<string, mixed>
$transform  : int

Methods

__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()

serialize()

public serialize(Traversable<string|int, QuadInterface>|array<string|int, QuadInterface$graph[, RdfNamespaceInterface|null $nmsp = null ]) : string
Parameters
$graph : Traversable<string|int, QuadInterface>|array<string|int, QuadInterface>
$nmsp : RdfNamespaceInterface|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

        
On this page

Search results