FileResolver
in package
A resolver ({@see Registry::putResolver()}) finding a struct's schema in `.dxns` files on disk, by the convention DXNS.md §6 states for every implementation -- so one set of schema files serves them all.
Mirrors Dextrin.Schema.FileResolver. Swappable like any resolver:
anyone with another convention writes their own.
The convention. A name is segments joined by ., with at most one
/ between a namespace and a name (Foo.Bar/Baz); every segment is a
directory but the last, which names the file. A schema of version N
named Foo.Bar/Baz is looked for, on each search path in order, in
Foo/Bar/Baz-vN.dxns (version 1 also Foo/Bar/Baz.dxns),
Foo/Bar/Baz/vN.dxns, Foo.Bar.Baz-vN.dxns (version 1 also
Foo.Bar.Baz.dxns), and the entry Baz in Foo.Bar.dxns, by its
%schema(N); a name with no / is its own namespace: Money in
Money.dxns.
- The first search path that has the name at all decides.
- A file's version is its schema's, or the file is refused.
- One version is found once: two files holding the same version are refused, naming both.
- Every version found is loaded, so an older struct reaches the materializer.
A refusal is a thrown SchemaCompileError (schema/compile).
Table of Contents
Methods
- forPaths() : Warning: Array to string conversion in /opt/phpdoc/src/phpDocumentor/Transformer/Writer/Twig/LinkRenderer/CallableAdapter.php on line 87 callable(string): Array
- A resolver searching `$searchPaths` in order.
- __construct() : mixed
-
candidates()
: array{0: string, 1: list
} - The entry a file holds the schema under -- the name after its `/`, or the whole name when it has none -- and every file that may hold it, with the version its name says (`null` for the namespace file, which holds whichever its `%schema(N)` says).
- inPath() : array<int, Compiled>|null
- Every version of `$name` `$dir` holds, each under the name asked for, or null when it holds none, so the next search path is asked.
- keyName() : string
- load() : array<int, Compiled, 2: string}>
- The versions of `$entry` in `$file`: none when the file is not there or holds no such entry. A file that does not compile, or holds another version than its name says, is refused.
- normalized() : string
- `$file` with its `./` and `//` taken out, so one file is one candidate.
- numbered() : array<int, array{0: string, 1: int}>
- The files in `$dir` named `<prefix>N.dxns`, each with its version.
Methods
forPaths()
A resolver searching `$searchPaths` in order.
public
static forPaths(array<int, string> $searchPaths) :
Warning: Array to string conversion in /opt/phpdoc/src/phpDocumentor/Transformer/Writer/Twig/LinkRenderer/CallableAdapter.php on line 87
callable(string): Array
Parameters
- $searchPaths : array<int, string>
Return values
Warning: Array to string conversion in /opt/phpdoc/src/phpDocumentor/Transformer/Writer/Twig/LinkRenderer/CallableAdapter.php on line 87 callable(string): Array__construct()
private
__construct() : mixed
candidates()
The entry a file holds the schema under -- the name after its `/`, or the whole name when it has none -- and every file that may hold it, with the version its name says (`null` for the namespace file, which holds whichever its `%schema(N)` says).
private
static candidates(string $dir, string $name) : array{0: string, 1: list}
Parameters
- $dir : string
- $name : string
Return values
array{0: string, 1: listinPath()
Every version of `$name` `$dir` holds, each under the name asked for, or null when it holds none, so the next search path is asked.
private
static inPath(string $dir, string $name) : array<int, Compiled>|null
Parameters
- $dir : string
- $name : string
Return values
array<int, Compiled>|nullkeyName()
private
static keyName(mixed $key) : string
Parameters
- $key : mixed
Return values
stringload()
The versions of `$entry` in `$file`: none when the file is not there or holds no such entry. A file that does not compile, or holds another version than its name says, is refused.
private
static load(string $file, string $entry, int|null $expected, string $dir, string $name) : array<int, Compiled, 2: string}>
The file is compiled as a tree compiles it (Tree): its entries
under their full names (DXNS.md §6), over the named types the rest
of its search path $dir defines -- so a field naming another
file's shape or named type resolves.
Parameters
- $file : string
- $entry : string
- $expected : int|null
- $dir : string
- $name : string
Return values
array<int, Compiled, 2: string}>normalized()
`$file` with its `./` and `//` taken out, so one file is one candidate.
private
static normalized(string $file) : string
Parameters
- $file : string
Return values
stringnumbered()
The files in `$dir` named `<prefix>N.dxns`, each with its version.
private
static numbered(string $dir, string $prefix) : array<int, array{0: string, 1: int}>
Parameters
- $dir : string
- $prefix : string