Registry
in package
Extension point for both `struct` and `custom-tag` decoding/encoding.
No entry for a given name -> decode falls back to an opaque DXNStruct/DXNCustomTag -- never a hard failure, since neither type requires a registration to be representable at all.
Struct entries only ever come from a compiled .dxns schema
(Compiler) plus an optional
materializer layered on top -- there is no putStruct that
hand-writes a struct's shape directly, because struct is
schema-dependent by design: the schema supplies field
names/order/types, a materializer only decides what nicer decoded
shape to produce from an already-schema-validated field map.
Immutable-by-convention: every put* method returns a new
Registry, never mutates $this -- threaded explicitly through
decode/encode/Schema::compile, never a global or a class with
hidden state.
Deliberate omission vs. the Elixir and JS ports: no
trusted/putTrusted. Both mirror it purely to gate whether
keyword decodes as an interned atom/Symbol.for (trusted) or a
plain wrapper (untrusted) -- this port's keyword always decodes as
DXNKeyword regardless, since PHP has
no atom table or global symbol registry whose exhaustion untrusted
input could threaten in the first place (see DXNKeyword's own
doc).
Table of Contents
Properties
- $materializers : array<string, callable(array<string, mixed>): mixed>
- $resolver : Warning: Array to string conversion in /opt/phpdoc/src/phpDocumentor/Transformer/Writer/Twig/LinkRenderer/CallableAdapter.php on line 87 callable(string): Array|null
- $structModules : array<string, class-string>
- $structs : array<string, Compiled>
- $tagEncoders : array<class-string, array{0: string, 1: callable}>
- $tags : array<string, callable(mixed): mixed>
- $typeAliases : array<string, TypeExpr>
Methods
- fetchMaterializer() : callable(array<string, mixed>): mixed|null
- fetchSchemaNameForModule() : string|null
- The reverse of {@see self::fetchStructModule()}: given an application value's own class, finds the schema name it was registered under (if any) -- what lets automatic encode-time validation recognize a plain PHP class instance as "this is a Foo" without being told so explicitly.
- fetchStructModule() : class-string|null
- fetchStructSchema() : FetchedSchema|null
- Looks up a compiled schema by struct name, consulting the lazy resolver (if any) on a miss and caching the result. Whether schemas are all compiled up front or resolved on demand (a resolver reading a file, calling a schema service, ...) is entirely the caller's choice -- this is what makes both paths look identical to everything else, which never needs to know which one is in play.
- fetchTag() : callable(mixed): mixed|null
- fetchTagEncoder() : array{0: string, 1: callable}|null
- fetchTypeAlias() : TypeExpr|null
- putResolver() : self
- putStructMaterializer() : self
- putStructModule() : self
- Declares which PHP class a schema's data is expected to be -- used only for `{form: 'reference', name}` checks during encode-time validation. Decode-time reference checks don't need this: they carry an internal provenance marker regardless of materializer shape ({@see \JOetjen\Dextrin\Schema\Validated}).
- putStructSchema() : self
- putTag() : self
- putTagEncoder() : self
- The reverse of {@see self::putTag()}: registers how to turn an application value (keyed by its class) back into `@name value` on encode -- decode-side dispatch happens by wire tag name, encode needs to dispatch by PHP class instead, so the two directions need separate tables.
- putTypeAlias() : self
- typeAliases() : array<string, TypeExpr>
- clone() : self
Properties
$materializers
private
array<string, callable(array<string, mixed>): mixed>
$materializers
= []
struct name -> materializer.
$resolver
private
Warning: Array to string conversion in /opt/phpdoc/src/phpDocumentor/Transformer/Writer/Twig/LinkRenderer/CallableAdapter.php on line 87
callable(string): Array|null
$resolver
= null
$structModules
private
array<string, class-string>
$structModules
= []
struct name -> PHP class.
$structs
private
array<string, Compiled>
$structs
= []
struct name -> compiled schema.
$tagEncoders
private
array<class-string, array{0: string, 1: callable}>
$tagEncoders
= []
class -> [tag name, encoder].
$tags
private
array<string, callable(mixed): mixed>
$tags
= []
tag name -> decoder.
$typeAliases
private
array<string, TypeExpr>
$typeAliases
= []
named type -> compiled type expression.
Methods
fetchMaterializer()
public
fetchMaterializer(string $name) : callable(array<string, mixed>): mixed|null
Parameters
- $name : string
Return values
callable(array<string, mixed>): mixed|nullfetchSchemaNameForModule()
The reverse of {@see self::fetchStructModule()}: given an application value's own class, finds the schema name it was registered under (if any) -- what lets automatic encode-time validation recognize a plain PHP class instance as "this is a Foo" without being told so explicitly.
public
fetchSchemaNameForModule(class-string $class) : string|null
Parameters
- $class : class-string
Return values
string|nullfetchStructModule()
public
fetchStructModule(string $name) : class-string|null
Parameters
- $name : string
Return values
class-string|nullfetchStructSchema()
Looks up a compiled schema by struct name, consulting the lazy resolver (if any) on a miss and caching the result. Whether schemas are all compiled up front or resolved on demand (a resolver reading a file, calling a schema service, ...) is entirely the caller's choice -- this is what makes both paths look identical to everything else, which never needs to know which one is in play.
public
fetchStructSchema(string $name) : FetchedSchema|null
Parameters
- $name : string
Return values
FetchedSchema|nullfetchTag()
public
fetchTag(string $name) : callable(mixed): mixed|null
Parameters
- $name : string
Return values
callable(mixed): mixed|nullfetchTagEncoder()
public
fetchTagEncoder(class-string $class) : array{0: string, 1: callable}|null
Parameters
- $class : class-string
Return values
array{0: string, 1: callable}|nullfetchTypeAlias()
public
fetchTypeAlias(string $name) : TypeExpr|null
Parameters
- $name : string
Return values
TypeExpr|nullputResolver()
public
putResolver(
Warning: Array to string conversion in /opt/phpdoc/src/phpDocumentor/Transformer/Writer/Twig/LinkRenderer/CallableAdapter.php on line 87
callable(string): Array $resolver) : self
Parameters
- $resolver : Warning: Array to string conversion in /opt/phpdoc/src/phpDocumentor/Transformer/Writer/Twig/LinkRenderer/CallableAdapter.php on line 87 callable(string): Array
Return values
selfputStructMaterializer()
public
putStructMaterializer(string $name, callable(array<string, mixed>): mixed $materializer) : self
Parameters
- $name : string
- $materializer : callable(array<string, mixed>): mixed
Return values
selfputStructModule()
Declares which PHP class a schema's data is expected to be -- used only for `{form: 'reference', name}` checks during encode-time validation. Decode-time reference checks don't need this: they carry an internal provenance marker regardless of materializer shape ({@see \JOetjen\Dextrin\Schema\Validated}).
public
putStructModule(string $name, class-string $class) : self
Parameters
- $name : string
- $class : class-string
Return values
selfputStructSchema()
public
putStructSchema(string $name, Compiled $compiled) : self
Parameters
- $name : string
- $compiled : Compiled
Return values
selfputTag()
public
putTag(string $name, callable(mixed): mixed $decoder) : self
Parameters
- $name : string
- $decoder : callable(mixed): mixed
Return values
selfputTagEncoder()
The reverse of {@see self::putTag()}: registers how to turn an application value (keyed by its class) back into `@name value` on encode -- decode-side dispatch happens by wire tag name, encode needs to dispatch by PHP class instead, so the two directions need separate tables.
public
putTagEncoder(class-string $class, string $name, callable(object): mixed $encoder) : self
Parameters
- $class : class-string
- $name : string
- $encoder : callable(object): mixed
Return values
selfputTypeAlias()
public
putTypeAlias(string $name, TypeExpr $typeExpr) : self
Parameters
- $name : string
- $typeExpr : TypeExpr
Return values
selftypeAliases()
public
typeAliases() : array<string, TypeExpr>
Return values
array<string, TypeExpr>clone()
private
clone() : self