Skip to content

Overview

Toolkit

The toolkit works with types as data: every package reads or writes the same tree of TypeLang\Type\* nodes.

Reflection "array<K, V>" /** @param */ reader parser phpdoc typesTypeLang\Type\* printer "array"

Everything speaks the same AST. Parse a string, read a reflection, print back, or walk the nodes with a visitor.

Package Does
type-lang/types The AST node classes, the vocabulary of the other parts
type-lang/parser String to AST, with grammar checking and feature flags
type-lang/printer AST to string: the full form or a native PHP type
type-lang/reader PHP Reflection to AST

Install what you need, types comes with any of them:

composer require type-lang/parser type-lang/printer
$parser = new TypeLang\Parser\TypeParser();
$type = $parser->parse('array{ key: int }');
echo new TypeLang\Printer\PrettyTypePrinter()->print($type); // array{key: int}
echo new TypeLang\Printer\NativeTypePrinter()->print($type); // array