You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The specification on types in DocBlocks (PSR-5) describes various keywords and special constructs
5
8
but also how to statically resolve the partial name of a Class into a Fully Qualified Class Name (FQCN).
@@ -22,8 +25,7 @@ The easiest way to install this library is with [Composer](https://getcomposer.o
22
25
23
26
## Examples
24
27
25
-
Ready to dive in and don't want to read through all that text below? Just consult the [examples](examples) folder and
26
-
check which type of action that your want to accomplish.
28
+
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.
27
29
28
30
## On Types and Element Names
29
31
@@ -59,8 +61,7 @@ Where the FqsenResolver can resolve:
59
61
60
62
## Resolving a type
61
63
62
-
In order to resolve a type you will have to instantiate the class `\phpDocumentor\Reflection\TypeResolver`
63
-
and call its `resolve` method like this:
64
+
In order to resolve a type you will have to instantiate the class `\phpDocumentor\Reflection\TypeResolver` and call its `resolve` method like this:
64
65
65
66
```php
66
67
$typeResolver = new \phpDocumentor\Reflection\TypeResolver();
@@ -71,31 +72,24 @@ In this example you will receive a Value Object of class `\phpDocumentor\Reflect
71
72
elements, one of type `\phpDocumentor\Reflection\Types\String_` and one of type
72
73
`\phpDocumentor\Reflection\Types\Integer`.
73
74
74
-
The real power of this resolver is in its capability to expand partial class names into fully qualified class names; but
75
-
in order to do that we need an additional `\phpDocumentor\Reflection\Types\Context` class that will inform the resolver
76
-
in which namespace the given expression occurs and which namespace aliases (or imports) apply.
75
+
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.
77
76
78
77
## Resolving an FQSEN
79
78
80
-
A Fully Qualified Structural Element Name is a reference to another element in your code bases and can be resolved using
81
-
the `\phpDocumentor\Reflection\FqsenResolver` class' `resolve` method, like this:
79
+
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:
82
80
83
81
```php
84
82
$fqsenResolver = new \phpDocumentor\Reflection\FqsenResolver();
In this example we resolve a Fully Qualified Structural Element Name (meaning that it includes the full namespace, class
89
-
name and element name) and receive a Value Object of type `\phpDocumentor\Reflection\Fqsen`.
86
+
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`.
90
87
91
-
The real power of this resolver is in its capability to expand partial element names into Fully Qualified Structural
92
-
Element Names; but in order to do that we need an additional `\phpDocumentor\Reflection\Types\Context` class that will
93
-
inform the resolver in which namespace the given expression occurs and which namespace aliases (or imports) apply.
88
+
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.
94
89
95
90
## Resolving partial Classes and Structural Element Names
96
91
97
-
Perhaps the best feature of this library is that it knows how to resolve partial class names into fully qualified class
98
-
names.
92
+
Perhaps the best feature of this library is that it knows how to resolve partial class names into fully qualified class names.
99
93
100
94
For example, you have this file:
101
95
@@ -117,9 +111,8 @@ class Classy
117
111
```
118
112
119
113
Suppose that you would want to resolve (and expand) the type in the `@var` tag and the element name in the `@see` tag.
120
-
For the resolvers to know how to expand partial names you have to provide a bit of _Context_ for them by instantiating
121
-
a new class named `\phpDocumentor\Reflection\Types\Context` with the name of the namespace and the aliases that are in
122
-
play.
114
+
115
+
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.
123
116
124
117
### Creating a Context
125
118
@@ -132,9 +125,7 @@ $context = new \phpDocumentor\Reflection\Types\Context(
132
125
);
133
126
```
134
127
135
-
Or by using the `\phpDocumentor\Reflection\Types\ContextFactory` to instantiate a new context based on a Reflector
136
-
object or by providing the namespace that you'd like to extract and the source code of the file in which the given
137
-
type expression occurs.
128
+
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.
138
129
139
130
```php
140
131
$contextFactory = new \phpDocumentor\Reflection\Types\ContextFactory();
After you have obtained a Context it is just a matter of passing it along with the `resolve` method of either Resolver
154
-
class as second argument and the Resolvers will take this into account when resolving partial names.
144
+
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.
155
145
156
146
To obtain the resolved class name for the `@var` tag in the example above you can do:
157
147
@@ -160,24 +150,17 @@ $typeResolver = new \phpDocumentor\Reflection\TypeResolver();
When you do this you will receive an object of class `\phpDocumentor\Reflection\Types\Object_` for which you can call
164
-
the `getFqsen` method to receive a Value Object that represents the complete FQSEN. So that would be
165
-
`phpDocumentor\Reflection\Types\Context`.
153
+
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`.
166
154
167
155
> Why is the FQSEN wrapped in another object `Object_`?
168
156
>
169
-
> The resolve method of the TypeResolver only returns object with the interface `Type` and the FQSEN is a common
170
-
> type that does not represent a Type. Also: in some cases a type can represent an "Untyped Object", meaning that it
171
-
> is an object (signified by the `object` keyword) but does not refer to a specific element using an FQSEN.
157
+
> 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.
172
158
173
-
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
174
-
resolve that you can do the following:
159
+
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:
175
160
176
161
```php
177
162
$fqsenResolver = new \phpDocumentor\Reflection\FqsenResolver();
Because Classy is a Class in the current namespace its FQSEN will have the `My\Example` namespace and by calling the
182
-
`resolve` method of the FQSEN Resolver you will receive an `Fqsen` object that refers to
183
-
`\My\Example\Classy::otherFunction()`.
166
+
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()`.
0 commit comments