php-dextrin

TypeExpr
in package

FinalYes

Internal, compiled representation of a `.dxns` type expression -- the 12-form vocabulary (`any`, `primitive`, `reference`, `list-of`, `set-of`, `tuple-of`, `map-of`, `enum`, `one-of`, `all-of`, `nilable`, `refine`) {@see Compiler} turns a parsed `.dxns` value into, and what {@see self::matches()} checks a decoded/to-be-encoded value against. (The 13th `dxn/DXN.md` ยง4 form, `struct`, isn't a distinct compiled shape here either -- a `%schema{}` entry compiles straight to {@see Compiled}, never to a `TypeExpr` a *field* could hold; `reference` is what a field uses to point at one.)

This vocabulary is fixed, not extensible from outside an actual library change -- what schema authors extend instead is composing these forms into a reusable named type, which needs no new form at all.

One field-per-form, all nullable except form itself, rather than a class hierarchy -- mirrors the JS port's own plain tagged-object representation ({form: 'list-of', elem: ...}) closely enough that porting Compiler/Coercion stays a mechanical translation.

Table of Contents

Constants

PRIMITIVES  : mixed = ['nil', 'boolean', 'integer', 'float', 'decimal...

Properties

$base  : self|null
$constraints  : array<string|int, mixed>|null
$elem  : self|null
$elems  : array<string|int, mixed>|null
$form  : string
$key  : self|null
$literals  : array<string|int, mixed>|null
$name  : string|null
$value  : self|null
$variants  : array<string|int, mixed>|null

Methods

allOf()  : self
any()  : self
enum()  : self
isPrimitiveName()  : bool
listOf()  : self
mapOf()  : self
matches()  : bool
Whether `$value` matches this type -- shared by both decode (`Validator::materialize()`) and encode-time validation (`Validator::validateForEncode()`): the same recursive check, the same method, for both directions.
nilable()  : self
oneOf()  : self
primitive()  : self
reference()  : self
refine()  : self
setOf()  : self
tupleOf()  : self
__construct()  : mixed
allMatch()  : bool
anyVariantMatches()  : bool
countOf()  : int
enumMatches()  : bool
everyVariantMatches()  : bool
isMultipleOf()  : bool
mapMatches()  : bool
A DXN map/ordered-map key can be any DXN value, but a bare PHP array's own key is always `int|string` (this port's own map-key coercion, see `MapBuilder`'s doc) -- `map-of`'s own `key:` type is therefore checked against that coerced PHP key directly, never the original pre-coercion DXN key.
matchesReference()  : bool
primitiveMatches()  : bool
satisfiesConstraint()  : bool
satisfiesConstraints()  : bool
toComparableFloat()  : float
toIntArg()  : int
tupleMatches()  : bool

Constants

PRIMITIVES

private mixed PRIMITIVES = ['nil', 'boolean', 'integer', 'float', 'decimal', 'rational', 'string', 'char', 'symbol', 'keyword', 'list', 'tuple', 'map', 'ordered-map', 'set', 'sorted-set', 'array', 'date', 'time', 'timestamp', 'datetime', 'duration', 'uuid', 'uri', 'bytes', 'regex']

Properties

$base read-only

public self|null $base = null

$constraints read-only

public array<string|int, mixed>|null $constraints = null

$elem read-only

public self|null $elem = null

$elems read-only

public array<string|int, mixed>|null $elems = null

$key read-only

public self|null $key = null

$literals read-only

public array<string|int, mixed>|null $literals = null

$name read-only

public string|null $name = null

$value read-only

public self|null $value = null

$variants read-only

public array<string|int, mixed>|null $variants = null

Methods

allOf()

public static allOf(array<int, self> $variants) : self
Parameters
$variants : array<int, self>
Return values
self

any()

public static any() : self
Return values
self

enum()

public static enum(array<int, mixed> $literals) : self
Parameters
$literals : array<int, mixed>
Return values
self

isPrimitiveName()

public static isPrimitiveName(string $name) : bool
Parameters
$name : string
Return values
bool

listOf()

public static listOf(self $elem) : self
Parameters
$elem : self
Return values
self

mapOf()

public static mapOf(self $key, self $value) : self
Parameters
$key : self
$value : self
Return values
self

matches()

Whether `$value` matches this type -- shared by both decode (`Validator::materialize()`) and encode-time validation (`Validator::validateForEncode()`): the same recursive check, the same method, for both directions.

public matches(mixed $value[, Registry|null $registry = null ]) : bool

{form: 'reference', name} checks the originating schema's name, not the value's own shape -- which is how it correctly rejects a materialized value that satisfies its own schema but is the wrong one for this field. Two sources carry that name: an opaque, unregistered DXNStruct carries its own wire name directly; a value that went through a registered schema (decode or encode-time validation alike) carries it via Validated. The third, encode-only source: $registry (null for decode, which never needs it) lets a real, unwrapped application class instance's own class be checked against whatever class was registered for name -- needed only for a value that turned out to have no schema of its own to be wrapped by.

Parameters
$value : mixed
$registry : Registry|null = null
Return values
bool

nilable()

public static nilable(self $elem) : self
Parameters
$elem : self
Return values
self

oneOf()

public static oneOf(array<int, self> $variants) : self
Parameters
$variants : array<int, self>
Return values
self

primitive()

public static primitive(string $name) : self
Parameters
$name : string
Return values
self

reference()

public static reference(string $name) : self
Parameters
$name : string
Return values
self

refine()

public static refine(self $base, array<string, mixed> $constraints) : self
Parameters
$base : self
$constraints : array<string, mixed>
Return values
self

setOf()

public static setOf(self $elem) : self
Parameters
$elem : self
Return values
self

tupleOf()

public static tupleOf(array<int, self> $elems) : self
Parameters
$elems : array<int, self>
Return values
self

__construct()

private __construct(string $form[, string|null $name = null ][, self|null $elem = null ][, array<int, self>|null $elems = null ][, self|null $key = null ][, self|null $value = null ][, array<int, mixed>|null $literals = null ][, array<int, self>|null $variants = null ][, self|null $base = null ][, array<string, mixed>|null $constraints = null ]) : mixed
Parameters
$form : string
$name : string|null = null
$elem : self|null = null
$elems : array<int, self>|null = null

tuple-of

$key : self|null = null
$value : self|null = null
$literals : array<int, mixed>|null = null

enum

$variants : array<int, self>|null = null

one-of / all-of

$base : self|null = null
$constraints : array<string, mixed>|null = null

refine

allMatch()

private static allMatch(self|null $elem, array<int, mixed> $items, Registry|null $registry) : bool
Parameters
$elem : self|null
$items : array<int, mixed>
$registry : Registry|null
Return values
bool

anyVariantMatches()

private anyVariantMatches(mixed $value, Registry|null $registry) : bool
Parameters
$value : mixed
$registry : Registry|null
Return values
bool

countOf()

private static countOf(mixed $value) : int
Parameters
$value : mixed
Return values
int

enumMatches()

private enumMatches(mixed $value) : bool
Parameters
$value : mixed
Return values
bool

everyVariantMatches()

private everyVariantMatches(mixed $value, Registry|null $registry) : bool
Parameters
$value : mixed
$registry : Registry|null
Return values
bool

isMultipleOf()

private static isMultipleOf(float $a, float $b) : bool
Parameters
$a : float
$b : float
Return values
bool

mapMatches()

A DXN map/ordered-map key can be any DXN value, but a bare PHP array's own key is always `int|string` (this port's own map-key coercion, see `MapBuilder`'s doc) -- `map-of`'s own `key:` type is therefore checked against that coerced PHP key directly, never the original pre-coercion DXN key.

private mapMatches(array<int|string, mixed> $value, Registry|null $registry) : bool
Parameters
$value : array<int|string, mixed>
$registry : Registry|null
Return values
bool

matchesReference()

private static matchesReference(string $name, mixed $value, Registry|null $registry) : bool
Parameters
$name : string
$value : mixed
$registry : Registry|null
Return values
bool

primitiveMatches()

private static primitiveMatches(string $name, mixed $value) : bool
Parameters
$name : string
$value : mixed
Return values
bool

satisfiesConstraint()

private static satisfiesConstraint(string $key, mixed $arg, mixed $value) : bool
Parameters
$key : string
$arg : mixed
$value : mixed
Return values
bool

satisfiesConstraints()

private static satisfiesConstraints(mixed $value, array<string, mixed> $constraints) : bool
Parameters
$value : mixed
$constraints : array<string, mixed>
Return values
bool

toComparableFloat()

private static toComparableFloat(mixed $value) : float
Parameters
$value : mixed
Return values
float

toIntArg()

private static toIntArg(mixed $arg) : int
Parameters
$arg : mixed
Return values
int

tupleMatches()

private tupleMatches(mixed $value, Registry|null $registry) : bool
Parameters
$value : mixed
$registry : Registry|null
Return values
bool
On this page

Search results