DXNStruct
in package
implements
DXNValueInterface
DXN `struct` (`%Name{...}` / `%Name[...]`), opaque without a schema. Keeps the keyed/positional shapes distinct rather than normalizing to one, same as the Elixir and JS ports -- `.dxnb` is always positional and can't recover field names without a schema.
This is decode's default representation for an unregistered struct
name; on encode, any plain PHP object with public properties is
also accepted directly (see Equality::kindOf()) without
needing to be built into a DXNStruct by hand first.
version is the schema version the struct was written with --
%Name(3){...}, DXNS.md §8 -- or null when it was written
without one.
extra holds the fields a struct carries beyond its declared ones
(DXNS.md §7), as [key, value] pairs in the order they were written:
a name for a named field, any other map key (§1.6) as itself. In text
they are entries after the fields or the items; in .dxnb, one
trailing tag-215 map.
Tags
Table of Contents
Interfaces
- DXNValueInterface
- Implemented by every `DXN*` wrapper class -- the PHP analog of the `dxnType` string tag used for kind dispatch in the JS port, and of `Dextrin.Value`'s closed type union in the Elixir original. Native PHP values (`null`, `bool`, `int`, `float`, `string`, and `array` for `map`/`array`) never implement this; {@see Equality::kindOf()} handles those directly.
Constants
- DXN_TYPE : mixed = 'struct'
Properties
- $extra : array<int, array{0: mixed, 1: mixed}>
- $kind : string
- $name : string
- $version : int|null
- $pairs : array<int, Pair>
- $values : array<int, mixed>
Methods
- compareTo() : int
- A total order against any other DXN value, not just another instance of this class -- backs {@see DXNSortedSet}. Cross-kind ordering is implementation-defined per DXN.md; within a kind, uses the kind's own natural order where one exists, or a deterministic structural fallback where it doesn't.
- dxnType() : string
- The DXN type name this value represents, e.g. "symbol", "uuid".
- equals() : bool
- Structural equality, recursing into nested DXN values as needed.
- extraKey() : mixed
- An entry's key as an extra field's key: a keyword, symbol or string is a name (its text); any other map key (DXN.md §1.6) is kept as itself.
- head() : string
- How a struct literal opens: `%Name`, or `%Name(3)` when it carries a version. Shared by every writer, so they agree.
- isKeyed() : bool
- isPositional() : bool
- keyed() : self
- pairs() : array<int, Pair>
- parseTypeName() : array{0: string, 1: ?int}|null
- The other direction: a `.dxnb` type name read back into its name and version, or `null` when its version is not a positive integer.
- positional() : self
- typeName() : string
- The struct's name as `.dxnb` writes it: `Name`, or `Name(3)` when it carries a version (DXN.md §2.4, §4.8).
- values() : array<int, mixed>
- withPairs() : self
- This struct holding `$pairs` instead, and otherwise unchanged -- what every walk over a keyed struct's fields goes through, so a walk never rebuilds a struct from its name and loses its version.
- withValues() : self
- This struct holding `$values` instead, and otherwise unchanged -- the positional counterpart of {@see withPairs()}.
- withVersion() : self
- This struct carrying `$version` instead, and otherwise unchanged.
- __construct() : mixed
Constants
DXN_TYPE
private
mixed
DXN_TYPE
= 'struct'
Properties
$extra read-only
public
array<int, array{0: mixed, 1: mixed}>
$extra
$kind read-only
public
string
$kind
$name read-only
public
string
$name
$version read-only
public
int|null
$version
$pairs read-only
private
array<int, Pair>
$pairs
$values read-only
private
array<int, mixed>
$values
Methods
compareTo()
A total order against any other DXN value, not just another instance of this class -- backs {@see DXNSortedSet}. Cross-kind ordering is implementation-defined per DXN.md; within a kind, uses the kind's own natural order where one exists, or a deterministic structural fallback where it doesn't.
public
compareTo(mixed $other) : int
Parameters
- $other : mixed
Return values
intdxnType()
The DXN type name this value represents, e.g. "symbol", "uuid".
public
dxnType() : string
Return values
stringequals()
Structural equality, recursing into nested DXN values as needed.
public
equals(mixed $other) : bool
Parameters
- $other : mixed
Return values
boolextraKey()
An entry's key as an extra field's key: a keyword, symbol or string is a name (its text); any other map key (DXN.md §1.6) is kept as itself.
public
static extraKey(mixed $key) : mixed
Parameters
- $key : mixed
head()
How a struct literal opens: `%Name`, or `%Name(3)` when it carries a version. Shared by every writer, so they agree.
public
static head(string $name[, int|null $version = null ]) : string
Parameters
- $name : string
- $version : int|null = null
Return values
stringisKeyed()
public
isKeyed() : bool
Return values
boolisPositional()
public
isPositional() : bool
Return values
boolkeyed()
public
static keyed(string $name, array<string|int, Pair> $pairs[, int|null $version = null ][, array<string|int, array{0: mixed, 1: mixed}> $extra = [] ]) : self
Parameters
- $name : string
- $pairs : array<string|int, Pair>
- $version : int|null = null
- $extra : array<string|int, array{0: mixed, 1: mixed}> = []
Return values
selfpairs()
public
pairs() : array<int, Pair>
Return values
array<int, Pair>parseTypeName()
The other direction: a `.dxnb` type name read back into its name and version, or `null` when its version is not a positive integer.
public
static parseTypeName(string $text) : array{0: string, 1: ?int}|null
Parameters
- $text : string
Return values
array{0: string, 1: ?int}|nullpositional()
public
static positional(string $name, array<string|int, mixed> $values[, int|null $version = null ][, array<string|int, array{0: mixed, 1: mixed}> $extra = [] ]) : self
Parameters
- $name : string
- $values : array<string|int, mixed>
- $version : int|null = null
- $extra : array<string|int, array{0: mixed, 1: mixed}> = []
Return values
selftypeName()
The struct's name as `.dxnb` writes it: `Name`, or `Name(3)` when it carries a version (DXN.md §2.4, §4.8).
public
static typeName(string $name[, int|null $version = null ]) : string
Parameters
- $name : string
- $version : int|null = null
Return values
stringvalues()
public
values() : array<int, mixed>
Return values
array<int, mixed>withPairs()
This struct holding `$pairs` instead, and otherwise unchanged -- what every walk over a keyed struct's fields goes through, so a walk never rebuilds a struct from its name and loses its version.
public
withPairs(array<string|int, Pair> $pairs) : self
Parameters
- $pairs : array<string|int, Pair>
Return values
selfwithValues()
This struct holding `$values` instead, and otherwise unchanged -- the positional counterpart of {@see withPairs()}.
public
withValues(array<string|int, mixed> $values) : self
Parameters
- $values : array<string|int, mixed>
Return values
selfwithVersion()
This struct carrying `$version` instead, and otherwise unchanged.
public
withVersion(int|null $version) : self
Parameters
- $version : int|null
Return values
self__construct()
private
__construct(string $name, string $kind, array<int, Pair> $pairs, array<int, mixed> $values, int|null $version, array<int, array{0: mixed, 1: mixed}> $extra) : mixed
Parameters
- $name : string
- $kind : string
- $pairs : array<int, Pair>
- $values : array<int, mixed>
- $version : int|null
- $extra : array<int, array{0: mixed, 1: mixed}>