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](https://getcomposer.org) 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](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 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
elements, one of type `\phpDocumentor\Reflection\Types\String_` and one of type
`\phpDocumentor\Reflection\Types\Integer`.
The real power of this resolver is in its capability to expand partial class names into fully qualified class names; but
in order to do that we need an additional `\phpDocumentor\Reflection\Types\Context` class that will inform the resolver
in which namespace the given expression occurs and which namespace aliases (or imports) apply.
## Resolving an FQSEN
A Fully Qualified Structural Element Name is a reference to another element in your code bases and can be resolved using
the `\phpDocumentor\Reflection\FqsenResolver` class' `resolve` method, like this:
```php
$fqsenResolver = new \phpDocumentor\Reflection\FqsenResolver();
$fqsen = $fqsenResolver->resolve('\phpDocumentor\Reflection\FqsenResolver::resolve()');
```
In this example we resolve a Fully Qualified Structural Element Name (meaning that it includes the full namespace, class
name and element name) and receive a Value Object of type `\phpDocumentor\Reflection\Fqsen`.
The real power of this resolver is in its capability to expand partial element names into Fully Qualified Structural
Element Names; but in order to do that we need an additional `\phpDocumentor\Reflection\Types\Context` class that will
inform the resolver in which namespace the given expression occurs and which namespace aliases (or imports) apply.
## Resolving partial Classes and Structural Element Names
Perhaps the best feature of this library is that it knows how to resolve partial class names into fully qualified class
names.
For example, you have this file:
```php
namespace My\Example;
use phpDocumentor\Reflection\Types;
class Classy
{
/**
* @var Types\Context
* @see Classy::otherFunction()
*/
public function __construct($context) {}
public function otherFunction(){}
}
```
Suppose that you would want to resolve (and expand) the type in the `@var` tag and the element name in the `@see` tag.
For the resolvers to know how to expand partial names you have to provide a bit of _Context_ for them by instantiating
a new class named `\phpDocumentor\Reflection\Types\Context` with the name of the namespace and the aliases that are in
play.
### Creating a Context
You can do this by manually creating a Context like this:
```php
$context = new \phpDocumentor\Reflection\Types\Context(
'\My\Example',
[ 'Types' => '\phpDocumentor\Reflection\Types']
);
```
Or by using the `\phpDocumentor\Reflection\Types\ContextFactory` to instantiate a new context based on a Reflector
object or by providing the namespace that you'd like to extract and the source code of the file in which the given
type expression occurs.
```php
$contextFactory = new \phpDocumentor\Reflection\Types\ContextFactory();
$context = $contextFactory->createFromReflector(new ReflectionMethod('\My\Example\Classy', '__construct'));
```
or
```php
$contextFactory = new \phpDocumentor\Reflection\Types\ContextFactory();
$context = $contextFactory->createForNamespace('\My\Example', file_get_contents('My/Example/Classy.php'));
```
### Using the Context
After you have obtained a Context it is just a matter of passing it along with the `resolve` method of either Resolver
class as second argument and the Resolvers will take this into account when resolving partial names.
To obtain the resolved class name for the `@var` tag in the example above you can do:
```php
$typeResolver = new \phpDocumentor\Reflection\TypeResolver();
$type = $typeResolver->resolve('Types\Context', $context);
```
When you do this you will receive an object of class `\phpDocumentor\Reflection\Types\Object_` for which you can call
the `getFqsen` method to receive a Value Object that represents the complete FQSEN. So that would be
`phpDocumentor\Reflection\Types\Context`.
> Why is the FQSEN wrapped in another object `Object_`?
>
> The resolve method of the TypeResolver only returns object with the interface `Type` and the FQSEN is a common
> type that does not represent a Type. Also: in some cases a type can represent an "Untyped Object", meaning that it
> is an object (signified by the `object` keyword) but does not refer to a specific element using an FQSEN.
Another example is on how to resolve the FQSEN of a method as can be seen with the `@see` tag in the example above. To
resolve that you can do the following:
```php
$fqsenResolver = new \phpDocumentor\Reflection\FqsenResolver();
$type = $fqsenResolver->resolve('Classy::otherFunction()', $context);
```
Because Classy is a Class in the current namespace its FQSEN will have the `My\Example` namespace and by calling the
`resolve` method of the FQSEN Resolver you will receive an `Fqsen` object that refers to
`\My\Example\Classy::otherFunction()`.
没有合适的资源?快使用搜索试试~ 我知道了~
功能模块 幸福一生婚庆 版本号:3.3.3 – 商用运营版 模板消息修改
共1222个文件
php:614个
phpt:136个
gif:135个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 123 浏览量
2022-03-21
09:53:18
上传
评论
收藏 3.07MB ZIP 举报
温馨提示
模块幸福一生婚庆_3.3.3_xc_wedding 小编已测试,小程序登录稍微有点问题,应该跟框架有点关系,但不影响正常使用,可以过审。 模块可能存在部分WQ2c(goto)加密,可付费解密,不解密也不影响程序使用。 提供小程序前端,使用微信开发者工具上传提交审核。
资源推荐
资源详情
资源评论
收起资源包目录
功能模块 幸福一生婚庆 版本号:3.3.3 – 商用运营版 模板消息修改 (1222个子文件)
bootstrap.min.css 115KB
sweetalert2.css 15KB
sweetalert2.min.css 10KB
nv.d3.min.css 9KB
style.css 4KB
style.css 2KB
dashboard.html.dist 7KB
file.html.dist 3KB
TestCaseMethod.tpl.dist 3KB
directory.html.dist 2KB
mocked_class.tpl.dist 1KB
file_item.html.dist 871B
phpunit.xml.dist 836B
directory_item.html.dist 821B
proxied_method.tpl.dist 716B
phpunit.xml.dist 681B
phpunit.xml.dist 677B
mocked_method.tpl.dist 644B
method_item.html.dist 632B
coverage_bar.html.dist 305B
mocked_class_method.tpl.dist 237B
wsdl_class.tpl.dist 179B
unmocked_clone.tpl.dist 159B
mocked_static_method.tpl.dist 151B
mocked_clone.tpl.dist 132B
wsdl_method.tpl.dist 60B
trait_class.tpl.dist 55B
glyphicons-halflings-regular.eot 20KB
35.gif 13KB
42.gif 13KB
40.gif 10KB
18.gif 8KB
19.gif 8KB
11.gif 8KB
32.gif 7KB
49.gif 6KB
29.gif 6KB
97.gif 5KB
65.gif 5KB
31.gif 5KB
46.gif 5KB
57.gif 5KB
45.gif 5KB
08.gif 5KB
43.gif 4KB
33.gif 4KB
68.gif 4KB
26.gif 4KB
14.gif 4KB
07.gif 4KB
51.gif 4KB
10.gif 4KB
47.gif 4KB
72.gif 4KB
06.gif 3KB
94.gif 3KB
84.gif 3KB
41.gif 3KB
17.gif 3KB
09.gif 3KB
28.gif 3KB
50.gif 3KB
95.gif 3KB
22.gif 3KB
27.gif 3KB
67.gif 3KB
90.gif 3KB
60.gif 3KB
58.gif 3KB
74.gif 2KB
25.gif 2KB
101.gif 2KB
54.gif 2KB
99.gif 2KB
24.gif 2KB
12.gif 2KB
73.gif 2KB
104.gif 2KB
103.gif 2KB
34.gif 2KB
88.gif 2KB
53.gif 2KB
04.gif 2KB
23.gif 2KB
05.gif 2KB
21.gif 2KB
03.gif 2KB
00.gif 2KB
20.gif 2KB
02.gif 2KB
39.gif 2KB
96.gif 2KB
30.gif 2KB
100.gif 2KB
48.gif 2KB
13.gif 2KB
38.gif 2KB
98.gif 2KB
83.gif 2KB
81.gif 2KB
共 1222 条
- 1
- 2
- 3
- 4
- 5
- 6
- 13
资源评论
智慧浩海
- 粉丝: 1w+
- 资源: 5103
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- tensorflow-gpu-2.7.3-cp39-cp39-manylinux2010-x86-64.whl
- tensorflow-2.8.0-cp37-cp37m-manylinux2010-x86-64.whl
- tensorflow-2.7.4-cp39-cp39-manylinux2010-x86-64.whl
- 个人资料-1111相关内容
- # C 语言介绍与使用技巧 ## C 语言简介:
- 3、高质量汽车租赁系统+layui)
- 介绍 Python 的一些基本信息,并分享一些使用技巧
- Qt的tcp网络编程(客户端和服务器)
- 当谈到 Linux 常用命令时,有很多命令可以提及 以下是一些常见的 Linux 命令及其功能:
- Sora AI Video Preview Case Sora AI 视频模版项目,React全栈快速部署.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功