@@ -61,8 +61,10 @@ Where the FqsenResolver can resolve:
61
61
In order to resolve a type you will have to instantiate the class ` \phpDocumentor\Reflection\TypeResolver `
62
62
and call its ` resolve ` method like this:
63
63
64
- $typeResolver = new \phpDocumentor\Reflection\TypeResolver();
65
- $type = $typeResolver->resolve('string|integer');
64
+ ``` php
65
+ $typeResolver = new \phpDocumentor\Reflection\TypeResolver();
66
+ $type = $typeResolver->resolve('string|integer');
67
+ ```
66
68
67
69
In this example you will receive a Value Object of class ` \phpDocumentor\Reflection\Types\Compound ` that has two
68
70
elements, one of type ` \phpDocumentor\Reflection\Types\String_ ` and one of type
@@ -77,8 +79,10 @@ in which namespace the given expression occurs and which namespace aliases (or i
77
79
A Fully Qualified Structural Element Name is a reference to another element in your code bases and can be resolved using
78
80
the ` \phpDocumentor\Reflection\FqsenResolver ` class' ` resolve ` method, like this:
79
81
80
- $fqsenResolver = new \phpDocumentor\Reflection\FqsenResolver();
81
- $fqsen = $fqsenResolver->resolve('\phpDocumentor\Reflection\FqsenResolver::resolve()');
82
+ ``` php
83
+ $fqsenResolver = new \phpDocumentor\Reflection\FqsenResolver();
84
+ $fqsen = $fqsenResolver->resolve('\phpDocumentor\Reflection\FqsenResolver::resolve()');
85
+ ```
82
86
83
87
In this example we resolve a Fully Qualified Structural Element Name (meaning that it includes the full namespace, class
84
88
name and element name) and receive a Value Object of type ` \phpDocumentor\Reflection\Fqsen ` .
95
99
For example, you have this file:
96
100
97
101
``` php
98
- <?php
99
102
namespace My\Example;
100
103
101
104
use phpDocumentor\Reflection\Types;
@@ -121,22 +124,28 @@ play.
121
124
122
125
You can do this by manually creating a Context like this:
123
126
124
- $context = new \phpDocumentor\Reflection\Types\Context(
125
- '\My\Example',
126
- [ 'Types' => '\phpDocumentor\Reflection\Types']
127
- );
127
+ ``` php
128
+ $context = new \phpDocumentor\Reflection\Types\Context(
129
+ '\My\Example',
130
+ [ 'Types' => '\phpDocumentor\Reflection\Types']
131
+ );
132
+ ```
128
133
129
134
Or by using the ` \phpDocumentor\Reflection\Types\ContextFactory ` to instantiate a new context based on a Reflector
130
135
object or by providing the namespace that you'd like to extract and the source code of the file in which the given
131
136
type expression occurs.
132
137
133
- $contextFactory = new \phpDocumentor\Reflection\Types\ContextFactory();
134
- $context = $contextFactory->createFromReflector(new ReflectionMethod('\My\Example\Classy', '__construct'));
138
+ ``` php
139
+ $contextFactory = new \phpDocumentor\Reflection\Types\ContextFactory();
140
+ $context = $contextFactory->createFromReflector(new ReflectionMethod('\My\Example\Classy', '__construct'));
141
+ ```
135
142
136
143
or
137
144
138
- $contextFactory = new \phpDocumentor\Reflection\Types\ContextFactory();
139
- $context = $contextFactory->createForNamespace('\My\Example', file_get_contents('My/Example/Classy.php'));
145
+ ``` php
146
+ $contextFactory = new \phpDocumentor\Reflection\Types\ContextFactory();
147
+ $context = $contextFactory->createForNamespace('\My\Example', file_get_contents('My/Example/Classy.php'));
148
+ ```
140
149
141
150
### Using the Context
142
151
@@ -145,8 +154,10 @@ class as second argument and the Resolvers will take this into account when reso
145
154
146
155
To obtain the resolved class name for the ` @var ` tag in the example above you can do:
147
156
148
- $typeResolver = new \phpDocumentor\Reflection\TypeResolver();
149
- $type = $typeResolver->resolve('Types\Context', $context);
157
+ ``` php
158
+ $typeResolver = new \phpDocumentor\Reflection\TypeResolver();
159
+ $type = $typeResolver->resolve('Types\Context', $context);
160
+ ```
150
161
151
162
When you do this you will receive an object of class ` \phpDocumentor\Reflection\Types\Object_ ` for which you can call
152
163
the ` getFqsen ` method to receive a Value Object that represents the complete FQSEN. So that would be
@@ -161,8 +172,10 @@ the `getFqsen` method to receive a Value Object that represents the complete FQS
161
172
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
162
173
resolve that you can do the following:
163
174
164
- $fqsenResolver = new \phpDocumentor\Reflection\FqsenResolver();
165
- $type = $fqsenResolver->resolve('Classy::otherFunction()', $context);
175
+ ``` php
176
+ $fqsenResolver = new \phpDocumentor\Reflection\FqsenResolver();
177
+ $type = $fqsenResolver->resolve('Classy::otherFunction()', $context);
178
+ ```
166
179
167
180
Because Classy is a Class in the current namespace its FQSEN will have the ` My\Example ` namespace and by calling the
168
181
` resolve ` method of the FQSEN Resolver you will receive an ` Fqsen ` object that refers to
0 commit comments