Compiler
in package
Compiles a parsed `.dxns` document (an ordinary decoded DXN value -- a `.dxns` file is valid `.dxn`, no new grammar; what makes it a *schema* document is purely the shape of the value it parses to: a `map` from name to type expression -- a bare PHP array in this port) into {@see Compiled} entries.
%schema}/%field} are recognized here directly, as DXNStruct instances named "schema"/"field" straight out of
Dextrin::decode() -- never looked up in a registry, the same way
built-in tags are recognized by name in the text/binary codecs
rather than registered. This sidesteps an obvious bootstrapping
question (doesn't parsing a .dxns file need a schema for its own
schema/field structs?) the same way JSON Schema's own vocabulary
is fixed tooling knowledge rather than itself validated against a
schema.
An entry whose value isn't a %schema} is a named type
instead: a reusable name for some combination of the fixed
type_expr vocabulary, e.g. PositiveInt: {:refine :integer {min: 1}} -- purely data, no PHP code, no registry callback, so any
conformant reader in any language resolves it the same way.
A struct's field names, and a document's own top-level entry names,
are always plain PHP strings by the time they reach this class --
Parser already reduces a %schema}'s
own keys (fields:, closed:, ...) to strings on the way in (its
own structFieldName()), and the document's top-level map keys
were already coerced to PHP array keys by MapBuilder -- unlike the
JS port's own entryName()/normalizeKeywords() helpers, neither
is needed here.
Table of Contents
Constants
- PRIMITIVES_ANY : mixed = 'any'
Methods
- compile() : Registry
- Compiles every entry of a decoded `.dxns` document into `$baseRegistry` -- a struct schema for each `%schema{}` entry, a named type_expr for every other entry. `$predicates` resolves `refine-fn:` names -- a plain array, not the struct registry itself, since a refine-fn is a validity check, not a decoder.
- __construct() : mixed
- compileAliases() : Registry
- compileEntry() : Compiled
- compileField() : Field
- compileFields() : array<int, Field>
- compileTypeExpr() : TypeExpr
- describe() : string
- getField() : mixed
- hasField() : bool
- literalName() : string
- resolveRefineFn() : Warning: Array to string conversion in /opt/phpdoc/src/phpDocumentor/Transformer/Writer/Twig/LinkRenderer/CallableAdapter.php on line 87 callable(array<string, mixed>): Array|null
Constants
PRIMITIVES_ANY
private
mixed
PRIMITIVES_ANY
= 'any'
Methods
compile()
Compiles every entry of a decoded `.dxns` document into `$baseRegistry` -- a struct schema for each `%schema{}` entry, a named type_expr for every other entry. `$predicates` resolves `refine-fn:` names -- a plain array, not the struct registry itself, since a refine-fn is a validity check, not a decoder.
public
static compile(mixed $schemaDoc, Registry $baseRegistry[,
Warning: Array to string conversion in /opt/phpdoc/src/phpDocumentor/Transformer/Writer/Twig/LinkRenderer/CallableAdapter.php on line 87
array<string, callable(array<string, mixed>): Array> $predicates = [] ]) : Registry
Named types defined in this document may reference any type
already known to $baseRegistry (from an earlier compile()
call), but not one declared alongside them in the same document
-- .dxns's own map type has no ordering guarantee to resolve
forward references against. A schema's fields, compiled
afterwards, can freely use any named type from either source.
Parameters
- $schemaDoc : mixed
- $baseRegistry : Registry
- $predicates : Warning: Array to string conversion in /opt/phpdoc/src/phpDocumentor/Transformer/Writer/Twig/LinkRenderer/CallableAdapter.php on line 87 array<string, callable(array<string, mixed>): Array> = []
Return values
Registry__construct()
private
__construct() : mixed
compileAliases()
private
static compileAliases(array<int, array{0: string, 1: mixed}> $aliasEntries, Registry $registry) : Registry
Parameters
- $aliasEntries : array<int, array{0: string, 1: mixed}>
- $registry : Registry
Return values
RegistrycompileEntry()
private
static compileEntry(DXNStruct $entry,
Warning: Array to string conversion in /opt/phpdoc/src/phpDocumentor/Transformer/Writer/Twig/LinkRenderer/CallableAdapter.php on line 87
array<string, callable(array<string, mixed>): Array> $predicates, array<string, TypeExpr> $aliases) : Compiled
Parameters
- $entry : DXNStruct
- $predicates : Warning: Array to string conversion in /opt/phpdoc/src/phpDocumentor/Transformer/Writer/Twig/LinkRenderer/CallableAdapter.php on line 87 array<string, callable(array<string, mixed>): Array>
- $aliases : array<string, TypeExpr>
Return values
CompiledcompileField()
private
static compileField(mixed $key, mixed $value, array<string, TypeExpr> $aliases) : Field
Parameters
- $key : mixed
- $value : mixed
- $aliases : array<string, TypeExpr>
Return values
FieldcompileFields()
private
static compileFields(mixed $value, array<string, TypeExpr> $aliases) : array<int, Field>
Parameters
- $value : mixed
- $aliases : array<string, TypeExpr>
Return values
array<int, Field>compileTypeExpr()
private
static compileTypeExpr(mixed $value, array<string, TypeExpr> $aliases) : TypeExpr
Parameters
- $value : mixed
- $aliases : array<string, TypeExpr>
Return values
TypeExprdescribe()
private
static describe(mixed $value) : string
Parameters
- $value : mixed
Return values
stringgetField()
private
static getField(array<int, array{0: string, 1: mixed}> $pairs, string $key[, mixed $fallback = null ]) : mixed
Parameters
- $pairs : array<int, array{0: string, 1: mixed}>
- $key : string
- $fallback : mixed = null
hasField()
private
static hasField(array<int, array{0: string, 1: mixed}> $pairs, string $key) : bool
Parameters
- $pairs : array<int, array{0: string, 1: mixed}>
- $key : string
Return values
boolliteralName()
private
static literalName(mixed $value) : string
Parameters
- $value : mixed
Return values
stringresolveRefineFn()
private
static resolveRefineFn(mixed $nameValue,
Warning: Array to string conversion in /opt/phpdoc/src/phpDocumentor/Transformer/Writer/Twig/LinkRenderer/CallableAdapter.php on line 87
array<string, callable(array<string, mixed>): Array> $predicates) :
Warning: Array to string conversion in /opt/phpdoc/src/phpDocumentor/Transformer/Writer/Twig/LinkRenderer/CallableAdapter.php on line 87
callable(array<string, mixed>): Array|null
Parameters
- $nameValue : mixed
- $predicates : Warning: Array to string conversion in /opt/phpdoc/src/phpDocumentor/Transformer/Writer/Twig/LinkRenderer/CallableAdapter.php on line 87 array<string, callable(array<string, mixed>): Array>