1 | <?php |
||
29 | class ReflectionEngine |
||
30 | { |
||
31 | /** |
||
32 | * @var null|LocatorInterface |
||
33 | */ |
||
34 | protected static $locator = null; |
||
35 | |||
36 | /** |
||
37 | * @var array|Node[] |
||
38 | */ |
||
39 | protected static $parsedFiles = array(); |
||
40 | |||
41 | /** |
||
42 | * @var null|integer |
||
43 | */ |
||
44 | protected static $maximumCachedFiles; |
||
45 | |||
46 | /** |
||
47 | * @var null|Parser |
||
48 | */ |
||
49 | protected static $parser = null; |
||
50 | |||
51 | /** |
||
52 | * @var null|NodeTraverser |
||
53 | */ |
||
54 | protected static $traverser = null; |
||
55 | |||
56 | /** |
||
57 | * @var null|Lexer |
||
58 | */ |
||
59 | protected static $lexer = null; |
||
60 | |||
61 | private function __construct() {} |
||
62 | |||
63 | 1 | public static function init(LocatorInterface $locator) |
|
89 | |||
90 | /** |
||
91 | * Limits number of files, that can be cached at any given moment |
||
92 | * |
||
93 | * @param integer $newLimit New limit |
||
94 | * |
||
95 | * @return void |
||
96 | */ |
||
97 | public static function setMaximumCachedFiles($newLimit) |
||
104 | |||
105 | /** |
||
106 | * Locates a file name for class |
||
107 | * |
||
108 | * @param string $fullClassName Full name of the class |
||
109 | * |
||
110 | * @return string |
||
111 | */ |
||
112 | 19 | public static function locateClassFile($fullClassName) |
|
130 | |||
131 | /** |
||
132 | * Tries to parse a class by name using LocatorInterface |
||
133 | * |
||
134 | * @param string $fullClassName Class name to load |
||
135 | * |
||
136 | * @return ClassLike |
||
137 | */ |
||
138 | 19 | public static function parseClass($fullClassName) |
|
159 | |||
160 | /** |
||
161 | * Parses class method |
||
162 | * |
||
163 | * @param string $fullClassName Name of the class |
||
164 | * @param string $methodName Name of the method |
||
165 | * |
||
166 | * @return ClassMethod |
||
167 | */ |
||
168 | public static function parseClassMethod($fullClassName, $methodName) |
||
181 | |||
182 | /** |
||
183 | * Parses class property |
||
184 | * |
||
185 | * @param string $fullClassName Name of the class |
||
186 | * @param string $propertyName Name of the property |
||
187 | * |
||
188 | * @return array Pair of [Property and PropertyProperty] nodes |
||
189 | */ |
||
190 | 1 | public static function parseClassProperty($fullClassName, $propertyName) |
|
207 | |||
208 | /** |
||
209 | * Parses a file and returns an AST for it |
||
210 | * |
||
211 | * @param string $fileName Name of the file |
||
212 | * @param string|null $fileContent Optional content of the file |
||
213 | * |
||
214 | * @return \PhpParser\Node[] |
||
215 | */ |
||
216 | 3046 | public static function parseFile($fileName, $fileContent = null) |
|
217 | { |
||
218 | 3046 | $fileName = PathResolver::realpath($fileName); |
|
219 | 3046 | if (isset(self::$parsedFiles[$fileName]) && !isset($fileContent)) { |
|
220 | 3044 | return self::$parsedFiles[$fileName]; |
|
221 | } |
||
222 | |||
223 | 9 | if (isset(self::$maximumCachedFiles) && (count(self::$parsedFiles) === self::$maximumCachedFiles)) { |
|
224 | array_shift(self::$parsedFiles); |
||
225 | } |
||
226 | |||
227 | 9 | if (!isset($fileContent)) { |
|
228 | 9 | $fileContent = file_get_contents($fileName); |
|
229 | } |
||
230 | 9 | $treeNode = self::$parser->parse($fileContent); |
|
231 | 9 | $treeNode = self::$traverser->traverse($treeNode); |
|
232 | |||
233 | 9 | self::$parsedFiles[$fileName] = $treeNode; |
|
234 | |||
235 | 9 | return $treeNode; |
|
236 | } |
||
237 | |||
238 | /** |
||
239 | * Parses a file namespace and returns an AST for it |
||
240 | * |
||
241 | * @param string $fileName Name of the file |
||
242 | * @param string $namespaceName Namespace name |
||
243 | * |
||
244 | * @return Namespace_ |
||
245 | * @throws ReflectionException |
||
246 | */ |
||
247 | 35 | public static function parseFileNamespace($fileName, $namespaceName) |
|
263 | |||
264 | } |
||
265 |