Skip to content

Library for parsing property types defined using var PHPDoc annotation

License

Notifications You must be signed in to change notification settings

vaniocz/type-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

82 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Type Parser

Build Status Coverage Status PHP7 License

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

<?php
use Doctrine\Common\Cache\FilesystemCache;
use Vanio\TypeParser\CachingParser;
use Vanio\TypeParser\Tests\Fixtures\Foo;
use Vanio\TypeParser\TypeParser;

$typeParser = new CachingParser(new TypeParser, new FilesystemCache(__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

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages