CycloneDX Library

JsonSerializer extends BaseSerializer
in package

Transform data models to JSON.

Tags
psalm-type

TNormalizedBom = array<string, mixed>

template-extends

BaseSerializer<TNormalizedBom>

author

jkowalleck

Table of Contents

Constants

JsonEncodeFlagsAllowedOptions  = 0 | \JSON_HEX_TAG | \JSON_HEX_AMP | \JSON_HEX_APOS | \JSON_HEX_QUOT | \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE
List of allowed options for {@see jsonEncodeFlags}.
JsonEncodeFlagsDefaultOptions  = 0 | \JSON_UNESCAPED_SLASHES
List of mandatory options for $jsonEncodeFlags.
JsonEncodeFlagsDefaults  = 0 | \JSON_THROW_ON_ERROR | \JSON_PRESERVE_ZERO_FRACTION
Defaults of {@see $jsonEncodeFlags}.

Properties

$jsonEncodeFlags  : int
Flags for {@see \json_encode()}.
$normalizerFactory  : NormalizerFactory

Methods

__construct()  : mixed
serialize()  : string
Serialize a {@see Bom} to string.
realNormalize()  : TNormalizedBom
Normalize a {@see Bom} to the data structure that {@see realSerialize()} can handle.
realSerialize()  : string
Serialize a {@see realNormalize() normalized} version of a {@see Bom}.
getAllBomRefs()  : array<string|int, BomRef>
Get a list of all {@see BomRef} in {@see Bom}.
normalize()  : TNormalizedBom
Normalize for serialization.

Constants

JsonEncodeFlagsAllowedOptions

List of allowed options for {@see jsonEncodeFlags}.

private int JsonEncodeFlagsAllowedOptions = 0 | \JSON_HEX_TAG | \JSON_HEX_AMP | \JSON_HEX_APOS | \JSON_HEX_QUOT | \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE

Bitmask consisting of JSON_*.

Some JSON flags could break the output, so they are not whitelisted.

Tags
see
https://www.php.net/manual/en/json.constants.php

Properties

Methods

__construct()

public __construct(NormalizerFactory $normalizerFactory[, int $jsonEncodeFlags = self::JsonEncodeFlagsDefaultOptions ]) : mixed
Parameters
$normalizerFactory : NormalizerFactory
$jsonEncodeFlags : int = self::JsonEncodeFlagsDefaultOptions

Bitmask consisting of JSON_*. see JsonEncodeFlagsAllowedOptions

serialize()

Serialize a {@see Bom} to string.

public final serialize(Bom $bom[, bool|null $prettyPrint = null ]) : string
Parameters
$bom : Bom

the BOM to serialize

$prettyPrint : bool|null = null

whether to beatify the resulting string. A null value means no preference.

Return values
string

realNormalize()

Normalize a {@see Bom} to the data structure that {@see realSerialize()} can handle.

protected realNormalize(Bom $bom) : TNormalizedBom
Parameters
$bom : Bom
Return values
TNormalizedBom

a version of the Bom that was normalized for serialization

realSerialize()

Serialize a {@see realNormalize() normalized} version of a {@see Bom}.

protected realSerialize(mixed $normalizedBom, bool|null $prettyPrint) : string
Parameters
$normalizedBom : mixed

a version of the Bom that was normalized for serialization

$prettyPrint : bool|null
Return values
string

getAllBomRefs()

Get a list of all {@see BomRef} in {@see Bom}.

private getAllBomRefs(Bom $bom) : array<string|int, BomRef>

The list might contain duplicates.

Parameters
$bom : Bom
Tags
psalm-return

list<BomRef>

Return values
array<string|int, BomRef>

normalize()

Normalize for serialization.

private normalize(Bom $bom) : TNormalizedBom

Also utilizes BomRefDiscriminator to guarantee that each BomRef has a unique value.

Parameters
$bom : Bom
Tags
throws
Exception
Return values
TNormalizedBom

a version of the Bom that was normalized for serialization


        
On this page

Search results