php-dextrin

Schema
in package

FinalYes

Public entry point for `.dxns` schema compilation and validation.

  • self::compile() -- the one-time walk from a decoded .dxns document to a populated Registry.
    • self::validate() -- checks an already-decoded value against a named schema (decode-side, but not decode itself -- see its own doc).
    • self::validateEncode()/self::validateEncodeTree() -- the encode-side mirror, one named schema vs. an automatic whole-tree walk. Unlike the Elixir original, both may transform the value they check (see Validator's own doc on schema-driven coercion).

Enforcement during actual decoding is fail-fast and automatic: every registered struct name is checked unconditionally as part of Dextrin::decode()/Dextrin::decodeBinary(). The methods here are for the cases that aren't "check while decoding" (see self::validate()'s own doc).

Table of Contents

Methods

compile()  : Registry
Compiles a decoded `.dxns` document into `$baseRegistry` -- a struct schema for each `%schema{}` entry, and a reusable named type for every other entry. `$predicates` resolves any `refine-fn:` names used in the document.
registerProvider()  : Registry
Compiles and registers one schema provider ({@see \JOetjen\Dextrin\Schema\Provider}) into `$registry` -- lets a class's own library ship its DXN schema without that library depending on this one.
validate()  : true
Validates an already-decoded value against a named, compiled schema -- for the cases that aren't "check while decoding": a value built directly in PHP before encoding, an opaque `DXNStruct` decoded before a schema became available, or checking against a different schema than the one originally used. Returns `true` on success, throws {@see SchemaValidationError} on failure.
validateEncode()  : mixed
Encode-time schema validation: checks `$value` -- ordinary PHP data you're about to encode -- against a named, compiled schema *before* encoding produces any output. The mirror image of {@see self::validate()}, for data on its way out rather than in.
validateEncodeTree()  : mixed
Automatic, name-driven encode-time validation: walks `$value` and checks *every* `DXNStruct` or registered application class instance anywhere in it against its own schema, wherever it turns out to be. Symmetric to how decode checks every named struct unconditionally. `Dextrin::encode()`/`encodeBinary()` call this automatically by default. Returns the (possibly-coerced) tree.
__construct()  : mixed

Methods

compile()

Compiles a decoded `.dxns` document into `$baseRegistry` -- a struct schema for each `%schema{}` entry, and a reusable named type for every other entry. `$predicates` resolves any `refine-fn:` names used in the document.

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
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

registerProvider()

Compiles and registers one schema provider ({@see \JOetjen\Dextrin\Schema\Provider}) into `$registry` -- lets a class's own library ship its DXN schema without that library depending on this one.

public static registerProvider(Registry $registry, DXNSchemaProvider $provider) : Registry
Parameters
$registry : Registry
$provider : DXNSchemaProvider
Return values
Registry

validate()

Validates an already-decoded value against a named, compiled schema -- for the cases that aren't "check while decoding": a value built directly in PHP before encoding, an opaque `DXNStruct` decoded before a schema became available, or checking against a different schema than the one originally used. Returns `true` on success, throws {@see SchemaValidationError} on failure.

public static validate(mixed $value, Registry $registry, string $schemaName) : true
Parameters
$value : mixed
$registry : Registry
$schemaName : string
Return values
true

validateEncode()

Encode-time schema validation: checks `$value` -- ordinary PHP data you're about to encode -- against a named, compiled schema *before* encoding produces any output. The mirror image of {@see self::validate()}, for data on its way out rather than in.

public static validateEncode(mixed $value, Registry $registry, string $schemaName[, bool $coerce = true ]) : mixed

Returns the checked value (possibly coerced -- see Validator's own doc), stripped of internal bookkeeping.

Parameters
$value : mixed
$registry : Registry
$schemaName : string
$coerce : bool = true

validateEncodeTree()

Automatic, name-driven encode-time validation: walks `$value` and checks *every* `DXNStruct` or registered application class instance anywhere in it against its own schema, wherever it turns out to be. Symmetric to how decode checks every named struct unconditionally. `Dextrin::encode()`/`encodeBinary()` call this automatically by default. Returns the (possibly-coerced) tree.

public static validateEncodeTree(mixed $value, Registry $registry[, bool $coerce = true ]) : mixed
Parameters
$value : mixed
$registry : Registry
$coerce : bool = true

__construct()

private __construct() : mixed
On this page

Search results