php-dextrin

Tree
in package

FinalYes

A tree of `.dxns` files read as one (Jan, 2026-10-20), the port of `Dextrin.Schema.Tree`: every entry named from where its file lies (DXNS.md §6, {@see Layout}), the files compiled in the order their references need -- so a reference to another file's named type resolves whatever order the files sort in -- and every problem reported with its file and line:

  • a file that is not DXN, or not a map of names to definitions;
  • a definition that does not compile;
  • a versioned file holding another version, and one version of a name held by two files;
  • files that need each other (a cycle across files is not resolved yet);
  • a name that resolves to nothing -- a typo such as acme.comon/Money -- unless its namespace is declared extern.

dextrin check is this, for CI.

Tags
phpstan-type

Problem array{file: string, line: int, message: string}

TreeFile array{file: string, source: string, doc: list<array{0: mixed, 1: mixed}>, keys: list, layout: Layout}

Table of Contents

Methods

load()  : Registry, summary: array{files: int, definitions: int}}|Problem>}
Every `.dxns` file under `$roots` (files or directories, searched recursively), compiled into one registry: `['ok' => true, 'registry' => ..., 'summary' => ['files' => n, 'definitions' => n]]`, or `['ok' => false, 'problems' => [...]]` with every problem found, in file and line order. `$extern` lists namespaces whose names are known to be supplied elsewhere.
namedTypes()  : array<string, TypeExpr>
The named types `$roots` define, compiled as {@see self::load()} compiles them but past any problem -- what a file of the tree needs from the others when it is compiled on its own ({@see FileResolver}).
__construct()  : mixed
compiled()  : Registry
entryLine()  : int
The line an entry's key stands on.
errorLine()  : int
The line of the entry a compile error names.
filesUnder()  : array<int, array{0: string, 1: string}>
firstLine()  : int|null
held()  : mixed
index()  : array<string, array<int, array{0: string, 1: int|string}>>
Every full name the tree defines, with the files and versions defining it.
isExtern()  : bool
keyName()  : string
lineAt()  : int
The line a code-point offset (the lexer's) falls on.
mentionLine()  : int
The first line that mentions `$name`, as a written reference.
needsOf()  : array<int, string>
The other files `$file` refers to.
order()  : array<int, TreeFile>
The files in an order that compiles each after every file it refers to; files that need each other are a problem, and are left out.
pairsOf()  : array<int, array{0: mixed, 1: mixed}>|null
problem()  : Problem
read()  : array<int, TreeFile>
referencesOf()  : array<int, string>
symbols()  : array<int, string>
twice()  : array<int, Problem>
One version of a name in two files (§4.6): found once, or refused naming both.
typeReferences()  : array<int, string>
unknown()  : array<int, Problem>
versionOf()  : int|string
versionProblem()  : Problem|null
A versioned file holds its entry as the version its name says.

Methods

load()

Every `.dxns` file under `$roots` (files or directories, searched recursively), compiled into one registry: `['ok' => true, 'registry' => ..., 'summary' => ['files' => n, 'definitions' => n]]`, or `['ok' => false, 'problems' => [...]]` with every problem found, in file and line order. `$extern` lists namespaces whose names are known to be supplied elsewhere.

public static load(array<int, string> $roots[, array<int, string> $extern = [] ][, Registry|null $base = null ]) : Registry, summary: array{files: int, definitions: int}}|Problem>}
Parameters
$roots : array<int, string>
$extern : array<int, string> = []
$base : Registry|null = null
Return values
Registry, summary: array{files: int, definitions: int}}|Problem>}

namedTypes()

The named types `$roots` define, compiled as {@see self::load()} compiles them but past any problem -- what a file of the tree needs from the others when it is compiled on its own ({@see FileResolver}).

public static namedTypes(array<int, string> $roots) : array<string, TypeExpr>
Parameters
$roots : array<int, string>
Return values
array<string, TypeExpr>

__construct()

private __construct() : mixed

compiled()

private static compiled(array<int, TreeFile> $files, Registry $registry, array<int, Problem> &$problems) : Registry
Parameters
$files : array<int, TreeFile>
$registry : Registry
$problems : array<int, Problem>
Return values
Registry

entryLine()

The line an entry's key stands on.

private static entryLine(TreeFile $file, string $key) : int
Parameters
$file : TreeFile
$key : string
Return values
int

errorLine()

The line of the entry a compile error names.

private static errorLine(TreeFile $file, string $message) : int
Parameters
$file : TreeFile
$message : string
Return values
int

filesUnder()

private static filesUnder(string $root) : array<int, array{0: string, 1: string}>
Parameters
$root : string
Return values
array<int, array{0: string, 1: string}>

firstLine()

private static firstLine(string $source, string $pattern) : int|null
Parameters
$source : string
$pattern : string
Return values
int|null

held()

private static held(TreeFile $file, string $key) : mixed
Parameters
$file : TreeFile
$key : string

index()

Every full name the tree defines, with the files and versions defining it.

private static index(array<int, TreeFile> $files) : array<string, array<int, array{0: string, 1: int|string}>>
Parameters
$files : array<int, TreeFile>
Return values
array<string, array<int, array{0: string, 1: int|string}>>

isExtern()

private static isExtern(string $name, array<int, string> $extern) : bool
Parameters
$name : string
$extern : array<int, string>
Return values
bool

keyName()

private static keyName(mixed $key) : string
Parameters
$key : mixed
Return values
string

lineAt()

The line a code-point offset (the lexer's) falls on.

private static lineAt(string $source, int|null $offset) : int
Parameters
$source : string
$offset : int|null
Return values
int

mentionLine()

The first line that mentions `$name`, as a written reference.

private static mentionLine(TreeFile $file, string $name) : int
Parameters
$file : TreeFile
$name : string
Return values
int

needsOf()

The other files `$file` refers to.

private static needsOf(TreeFile $file, array<string, array<int, array{0: string, 1: int|string}>> $index) : array<int, string>
Parameters
$file : TreeFile
$index : array<string, array<int, array{0: string, 1: int|string}>>
Return values
array<int, string>

order()

The files in an order that compiles each after every file it refers to; files that need each other are a problem, and are left out.

private static order(array<int, TreeFile> $files, array<string, array<int, array{0: string, 1: int|string}>> $index, array<int, Problem> &$problems) : array<int, TreeFile>
Parameters
$files : array<int, TreeFile>
$index : array<string, array<int, array{0: string, 1: int|string}>>
$problems : array<int, Problem>
Return values
array<int, TreeFile>

pairsOf()

private static pairsOf(mixed $doc) : array<int, array{0: mixed, 1: mixed}>|null
Parameters
$doc : mixed
Return values
array<int, array{0: mixed, 1: mixed}>|null

problem()

private static problem(string $file, int $line, string $message) : Problem
Parameters
$file : string
$line : int
$message : string
Return values
Problem

read()

private static read(array<int, string> $roots, array<int, Problem> &$problems) : array<int, TreeFile>
Parameters
$roots : array<int, string>
$problems : array<int, Problem>
Return values
array<int, TreeFile>

referencesOf()

private static referencesOf(Registry $registry, string $name) : array<int, string>
Parameters
$registry : Registry
$name : string
Return values
array<int, string>

symbols()

private static symbols(mixed $value) : array<int, string>
Parameters
$value : mixed
Return values
array<int, string>

twice()

One version of a name in two files (§4.6): found once, or refused naming both.

private static twice(array<string, array<int, array{0: string, 1: int|string}>> $index) : array<int, Problem>
Parameters
$index : array<string, array<int, array{0: string, 1: int|string}>>
Return values
array<int, Problem>

typeReferences()

private static typeReferences(TypeExpr|null $type) : array<int, string>
Parameters
$type : TypeExpr|null
Return values
array<int, string>

unknown()

private static unknown(array<int, TreeFile> $files, Registry $registry, array<string, mixed> $index, array<int, string> $extern) : array<int, Problem>
Parameters
$files : array<int, TreeFile>
$registry : Registry
$index : array<string, mixed>
$extern : array<int, string>
Return values
array<int, Problem>

versionOf()

private static versionOf(mixed $value) : int|string
Parameters
$value : mixed
Return values
int|string

versionProblem()

A versioned file holds its entry as the version its name says.

private static versionProblem(TreeFile $file) : Problem|null
Parameters
$file : TreeFile
Return values
Problem|null
On this page

Search results