Skip to content

Repository files navigation

Type Parser

Build StatusCoverage StatusPHP7License

Library for parsing type expressions and/or property types defined using var PHPDoc annotation almost as defined in PSR-5 specification draft, just a little bit more permissive. It also supports merging two (or more) types like int|string -> scalar or string[]|int[] -> scalar[]

PSR-5 ABNF: https://github.com/phpDocumentor/fig-standards/blob/master/proposed/phpdoc.md#user-content-abnf

Example

<?phpuseDoctrine\Common\Cache\FilesystemCache;
useVanio\TypeParser\CachingParser;
useVanio\TypeParser\Tests\Fixtures\Foo;
useVanio\TypeParser\TypeParser;
$typeParser = newCachingParser(newTypeParser, newFilesystemCache(__DIR__ . '/cache'));
$type = $typeParser->parsePropertyTypes(Foo::class);
$type['scalar']->type(); // /** @var int|string */ -> new CompoundType(Type::INTEGER, Type::STRING) -> new SimpleType(Type::SCALAR)

About

Library for parsing property types defined using var PHPDoc annotation

Resources

Stars

7 stars

Watchers

4 watching

Forks

Releases

Packages

Used by

Contributors

Languages