28
28
use function interface_exists ;
29
29
use function is_file ;
30
30
use function is_string ;
31
- use function restore_error_handler ;
32
- use function set_error_handler ;
33
- use function spl_autoload_functions ;
34
31
use function strtolower ;
35
32
use function trait_exists ;
36
33
use const PHP_VERSION_ID ;
@@ -180,8 +177,10 @@ public function locateIdentifier(Reflector $reflector, Identifier $identifier):
180
177
);
181
178
}
182
179
}
180
+
183
181
return null ;
184
182
}
183
+
185
184
[$ potentiallyLocatedFile , $ className , $ startLine ] = $ locateResult ;
186
185
187
186
return $ this ->findReflection ($ reflector , $ potentiallyLocatedFile , new Identifier ($ className , $ identifier ->getType ()), $ startLine );
@@ -259,23 +258,11 @@ public function locateIdentifiersByType(Reflector $reflector, IdentifierType $id
259
258
}
260
259
261
260
/**
262
- * Attempt to locate a class by name.
263
- *
264
- * If class already exists, simply use internal reflection API to get the
265
- * filename and store it.
266
- *
267
- * If class does not exist, we make an assumption that whatever autoloaders
268
- * that are registered will be loading a file. We then override the file://
269
- * protocol stream wrapper to "capture" the filename we expect the class to
270
- * be in, and then restore it. Note that class_exists will cause an error
271
- * that it cannot find the file, so we squelch the errors by overriding the
272
- * error handler temporarily.
273
- *
274
261
* @return array{string, string, int|null}|null
275
262
*/
276
263
private function locateClassByName (string $ className ): ?array
277
264
{
278
- if (class_exists ($ className, false ) || interface_exists ($ className, false ) || trait_exists ($ className, false )) {
265
+ if (class_exists ($ className ) || interface_exists ($ className ) || trait_exists ($ className )) {
279
266
$ reflection = new ReflectionClass ($ className );
280
267
$ filename = $ reflection ->getFileName ();
281
268
@@ -290,42 +277,7 @@ private function locateClassByName(string $className): ?array
290
277
return [$ filename , $ reflection ->getName (), $ reflection ->getStartLine () !== false ? $ reflection ->getStartLine () : null ];
291
278
}
292
279
293
- $ this ->silenceErrors ();
294
-
295
- try {
296
- /** @var array{string, string, null}|null */
297
- return FileReadTrapStreamWrapper::withStreamWrapperOverride (
298
- static function () use ($ className ): ?array {
299
- $ functions = spl_autoload_functions ();
300
- if ($ functions === false ) {
301
- return null ;
302
- }
303
-
304
- foreach ($ functions as $ preExistingAutoloader ) {
305
- $ preExistingAutoloader ($ className );
306
-
307
- /**
308
- * This static variable is populated by the side-effect of the stream wrapper
309
- * trying to read the file path when `include()` is used by an autoloader.
310
- *
311
- * This will not be `null` when the autoloader tried to read a file.
312
- */
313
- if (FileReadTrapStreamWrapper::$ autoloadLocatedFile !== null ) {
314
- return [FileReadTrapStreamWrapper::$ autoloadLocatedFile , $ className , null ];
315
- }
316
- }
317
-
318
- return null ;
319
- },
320
- );
321
- } finally {
322
- restore_error_handler ();
323
- }
324
- }
325
-
326
- private function silenceErrors (): void
327
- {
328
- set_error_handler (static fn (): bool => true );
280
+ return null ;
329
281
}
330
282
331
283
}
0 commit comments