phpDocumentor /TypeResolver
A PSR-5 based resolver of Class names, Types and Structural Element Names
★ 9,151⑂ 51👁 9⑃ 243● 64▤ 43
+0
日增长
9,151
stars
51
forks
9
watchers
243
prs
64
issues
43
releases
README
!
!Packagist Version
!Packagist Version
TypeResolver and FqsenResolver
==============================
The specification on types in DocBlocks (PSR-5) describes various keywords and special constructs
but also how to statically resolve the partial name of a Class into a Fully Qualified Class Name (FQCN).
PSR-5 also introduces an additional way to describe deeper elements than Classes, Interfaces and Traits
called the Fully Qualified Structural Element Name (FQSEN). Using this it is possible to refer to methods,
properties and class constants but also functions and global constants.
This package provides two Resolvers that are capable of
1. Returning a series of Value Object for given expression while resolving any partial class names, and
2. Returning an FQSEN object after resolving any partial Structural Element Names into Fully Qualified Structural
Element names.
Installing
The easiest way to install this library is with Composer using the following command:
$ composer require phpdocumentor/type-resolver
Examples
Ready to dive in and don't want to read through all that text below? Just consult the examples folder and check which type of action that your want to accomplish.
On Types and Element Names
This component can be used in one of two ways
1. To resolve a Type or
2. To resolve a Fully Qualified Structural Element Name
The big difference between these two is in the number of things it can resolve.
The TypeResolver can resolve:
- a php primitive or pseudo-primitive such as a string or void (@var string or @return void).
- a composite such as an array of string (@var string[]).
- a compound such as a string or integer (@var string|integer).
- an array expression (@var (string|TypeResolver)[])
- an object or interface such as the TypeResolver class (@var TypeResolver
or @var \phpDocumentor\Reflection\TypeResolver)
please note that if you want to pass partial class names that additional steps are necessary, see the
chapter Resolving partial classes and FQSENs for more information.
Where the FqsenResolver can resolve:
- Constant expressions (i.e. @see \MyNamespace\MY_CONSTANT)
- Function expressions (i.e. @see \MyNamespace\myFunction())
- Class expressions (i.e. @see \MyNamespace\MyClass)
- Interface expressions (i.e. @see \MyNamespace\MyInterface)
- Trait expressions (i.e. @see \MyNamespace\MyTrait)
- Class constant expressions (i.e. @see \MyNamespace\MyClass::MY_CONSTANT)
- Property expressions (i.e. @see \MyNamespace\MyClass::$myProperty)
- Method expressions (i.e. @see \MyNamespace\MyClass::myMethod())
Resolving a type
In order to resolve a type you will have to instantiate the class \phpDocumentor\Reflection\TypeResolver and call its resolve method like this:
php
$typeResolver = new \phpDocumentor\Reflection\TypeResolver();
$type = $typeResolver-resolve('string|integer');
In this example you will receive a Value Object of class \phpDocumentor\Reflection\Types\Compound that has two
elemeTop issues
#11ContextFactory overwrites when multiple imports with same alias9 comments · 2015-07-19#266Support class-string-map<T of Foo, T>5 comments · 2025-12-07#82resolvePartialStructuralElementName gives wrong namespace1 comments · 2019-10-30
Latest release
2.1.0 2.1.0 2026-09-28What's Changed Update .gitattributes by @williamdes in https://github.com/phpDocumentor/TypeResolver/pull/286 Support non-decimal-int-string by @oleibman in https://github.com/phpDocumentor/TypeResolver/pull/308 New Contributors @oleibman made their first contribution in https://github.com/phpDocumentor/TypeResolver/pull/308 Full Changelog: https://github.com/phpDocumentor/TypeResolver/compare/2.0.0...2.1.0