vanio / type-parser
Library for parsing property types defined using @var PHPDoc annotation
Installs: 17 915
Dependents: 4
Suggesters: 0
Security: 0
Stars: 7
Watchers: 5
Forks: 0
Open Issues: 0
Requires
- php: ^7.0
- doctrine/annotations: ^1.2
- doctrine/cache: ^1.6
Requires (Dev)
- phpunit/phpunit: ^6.5.14
- symfony/config: ^3.0
- symfony/dependency-injection: ^3.4.26
- symfony/http-foundation: ^3.4.35
- symfony/http-kernel: ^3.0
- vanio/coding-standards: ^0.2@dev
This package is auto-updated.
Last update: 2024-12-06 11:57:20 UTC
README
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)