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
Table of Contents
Interfaces
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
TRANSFORM_COMPACT
public
mixed
TRANSFORM_COMPACT
= 3
TRANSFORM_EXPAND
public
mixed
TRANSFORM_EXPAND
= 1
TRANSFORM_FLATTEN
public
mixed
TRANSFORM_FLATTEN
= 2
TRANSFORM_NONE
public
mixed
TRANSFORM_NONE
= 0
Properties
$baseUri
private
string|null
$baseUri
$context
private
mixed
$context
$jsonEncodeFlags
private
int
$jsonEncodeFlags
$options
private
array<string, mixed>
$options
$transform
private
int
$transform
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
orJsonLdSerializer::TRANSFORM_COMPACT
. In case ofJsonLdSerializer::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()
orML\JsonLD\JsonLD::flatten()
when$transform
equalsJsonLdSerializer::TRANSFORM_COMPACT
orJsonLdSerializer::TRANSFORM_FLATTEN
, repectively. - $options : array<string, mixed> = []
-
options to be passed to the corresponding
ML\JsonLD\JsonLD
method (expand()
,compact()
orflatten()
according to the$transform
parameter value). If you would like these methods to be better documented, then you are not then only one... :-(
Tags
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
Return values
stringserializeStream()
public
serializeStream(resource|StreamInterface $output, Traversable<string|int, QuadInterface>|array<string|int, QuadInterface> $graph[, RdfNamespaceInterface|null $nmsp = null ]) : void
Parameters
- $output : resource|StreamInterface
- $graph : Traversable<string|int, QuadInterface>|array<string|int, QuadInterface>
- $nmsp : RdfNamespaceInterface|null = null
-
unused but required for compatibility with the
\rdfInterface\Serializer
.