class Deserializer (View source)

Constants

protected MAX_NODES

The maximum number of schema fragments that may be expanded.

Properties

protected array<string,mixed> $root

The root schema being deserialized (used to resolve local $refs).

protected $nodes

The number of schema fragments expanded so far.

protected array<string,array<string,mixed>> $refCache

The cache of resolved local "$ref" targets, keyed by reference.

Methods

__construct(array $root)

Create a new deserializer instance.

static Type
deserialize(array $schema)

Deserialize the Laravel-supported JSON Schema subset into a type.

build(array $schema, array $refs = [])

Build a type from the given schema fragment.

AnyOfType|null
buildAnyOfComposition(array $schema, array $refs = [])

Build an anyOf composition unless it is the existing nullable single-schema form.

buildObject(array $schema, array $refs = [])

Build an object type from the given schema fragment.

buildArray(array $schema, array $refs = [])

Build an array type from the given schema fragment.

buildString(array $schema)

Build a string type from the given schema fragment.

buildInteger(array $schema)

Build an integer type from the given schema fragment.

buildNumber(array $schema)

Build a number type from the given schema fragment.

TType
applyNumericBounds(NumberType $type, array $schema, callable|null $cast = null)

Apply the numeric bound keywords to the given integer or number type.

void
applyCommon(Type $type, array $schema)

Apply the keywords shared by every type to the given instance.

array
resolveType(array $schema)

Resolve the base type name and whether the schema is nullable.

string|null
inferType(array $schema)

Infer the type name when "type" is absent but the shape is unambiguous.

string|null
inferEnumType(array $enum)

Infer the scalar type shared by a homogeneous enum of scalars.

void
ensureUnionConstraintsAreSupported(array $schema)

Ensure a multi-type union carries no type-specific constraint keywords.

array
normalizeUnions(array $schema, array $refs = [])

Collapse "anyOf" / "oneOf" null branches into a single effective schema.

bool
isNullBranch(array $branch)

Determine if the given schema branch describes only the "null" type.

array
resolveRef(array $schema, array $refs = [])

Resolve a local "$ref" against the root schema, merging sibling keys.

array
lookupRef(string $ref)

Look up a local JSON pointer reference within the root schema.

int|float|null
toNumber(mixed $value)

Normalize the given value to an integer or float, or null when not numeric.

int
toInteger(int|float $value)

Cast the given number to an integer, rejecting non-integer values.

Details

protected __construct(array $root)

Create a new deserializer instance.

Parameters

array $root

static Type deserialize(array $schema)

Deserialize the Laravel-supported JSON Schema subset into a type.

Parameters

array $schema

Return Value

Type

Exceptions

InvalidArgumentException

protected Type build(array $schema, array $refs = [])

Build a type from the given schema fragment.

Parameters

array $schema
array $refs

Return Value

Type

Exceptions

InvalidArgumentException

protected AnyOfType|null buildAnyOfComposition(array $schema, array $refs = [])

Build an anyOf composition unless it is the existing nullable single-schema form.

Parameters

array $schema
array $refs

Return Value

AnyOfType|null

Exceptions

InvalidArgumentException

protected ObjectType buildObject(array $schema, array $refs = [])

Build an object type from the given schema fragment.

Parameters

array $schema
array $refs

Return Value

ObjectType

Exceptions

InvalidArgumentException

protected ArrayType buildArray(array $schema, array $refs = [])

Build an array type from the given schema fragment.

Parameters

array $schema
array $refs

Return Value

ArrayType

Exceptions

InvalidArgumentException

protected StringType buildString(array $schema)

Build a string type from the given schema fragment.

Parameters

array $schema

Return Value

StringType

protected IntegerType buildInteger(array $schema)

Build an integer type from the given schema fragment.

Parameters

array $schema

Return Value

IntegerType

protected NumberType buildNumber(array $schema)

Build a number type from the given schema fragment.

Parameters

array $schema

Return Value

NumberType

protected TType applyNumericBounds(NumberType $type, array $schema, callable|null $cast = null)

Apply the numeric bound keywords to the given integer or number type.

Parameters

NumberType $type
array $schema
callable|null $cast

Return Value

TType

Exceptions

InvalidArgumentException

protected void applyCommon(Type $type, array $schema)

Apply the keywords shared by every type to the given instance.

Parameters

Type $type
array $schema

Return Value

void

Exceptions

InvalidArgumentException

protected array resolveType(array $schema)

Resolve the base type name and whether the schema is nullable.

Parameters

array $schema

Return Value

array

Exceptions

InvalidArgumentException

protected string|null inferType(array $schema)

Infer the type name when "type" is absent but the shape is unambiguous.

Parameters

array $schema

Return Value

string|null

protected string|null inferEnumType(array $enum)

Infer the scalar type shared by a homogeneous enum of scalars.

Parameters

array $enum

Return Value

string|null

protected void ensureUnionConstraintsAreSupported(array $schema)

Ensure a multi-type union carries no type-specific constraint keywords.

Parameters

array $schema

Return Value

void

Exceptions

InvalidArgumentException

protected array normalizeUnions(array $schema, array $refs = [])

Collapse "anyOf" / "oneOf" null branches into a single effective schema.

Parameters

array $schema
array $refs

Return Value

array

Exceptions

InvalidArgumentException

protected bool isNullBranch(array $branch)

Determine if the given schema branch describes only the "null" type.

Parameters

array $branch

Return Value

bool

protected array resolveRef(array $schema, array $refs = [])

Resolve a local "$ref" against the root schema, merging sibling keys.

Parameters

array $schema
array $refs

Return Value

array

Exceptions

InvalidArgumentException

protected array lookupRef(string $ref)

Look up a local JSON pointer reference within the root schema.

Parameters

string $ref

Return Value

array

Exceptions

InvalidArgumentException

protected int|float|null toNumber(mixed $value)

Normalize the given value to an integer or float, or null when not numeric.

Parameters

mixed $value

Return Value

int|float|null

protected int toInteger(int|float $value)

Cast the given number to an integer, rejecting non-integer values.

Parameters

int|float $value

Return Value

int

Exceptions

InvalidArgumentException