Skip to content

Commit 442e489

Browse files
committed
Merge branch '1.6.x' into 1.7.x
2 parents c5952f0 + 28eaba2 commit 442e489

File tree

2 files changed

+36
-16
lines changed

2 files changed

+36
-16
lines changed

src/Reflection/BetterReflection/SourceLocator/AutoloadSourceLocator.php

+29-8
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
use function interface_exists;
2929
use function is_file;
3030
use function is_string;
31+
use function opcache_invalidate;
3132
use function restore_error_handler;
3233
use function set_error_handler;
3334
use function spl_autoload_functions;
@@ -134,12 +135,23 @@ public function locateIdentifier(Reflector $reflector, Identifier $identifier):
134135
if ($locateResult === null) {
135136
return null;
136137
}
137-
[$potentiallyLocatedFile, $className, $startLine] = $locateResult;
138+
[$potentiallyLocatedFiles, $className, $startLine] = $locateResult;
138139
if ($startLine !== null) {
139140
$this->startLineByClass[strtolower($className)] = $startLine;
140141
}
141142

142-
return $this->findReflection($reflector, $potentiallyLocatedFile, new Identifier($className, $identifier->getType()), $startLine);
143+
$newIdentifier = new Identifier($className, $identifier->getType());
144+
145+
foreach ($potentiallyLocatedFiles as $potentiallyLocatedFile) {
146+
$reflection = $this->findReflection($reflector, $potentiallyLocatedFile, $newIdentifier, $startLine);
147+
if ($reflection === null) {
148+
continue;
149+
}
150+
151+
return $reflection;
152+
}
153+
154+
return null;
143155
}
144156

145157
private function findReflection(Reflector $reflector, string $file, Identifier $identifier, ?int $startLine): ?Reflection
@@ -312,7 +324,7 @@ private function getReflectionClass(string $className): ?ReflectionClass
312324
* that it cannot find the file, so we squelch the errors by overriding the
313325
* error handler temporarily.
314326
*
315-
* @return array{string, string, int|null}|null
327+
* @return array{string[], string, int|null}|null
316328
*/
317329
private function locateClassByName(string $className): ?array
318330
{
@@ -323,7 +335,7 @@ private function locateClassByName(string $className): ?array
323335
return null;
324336
}
325337

326-
return [$filename, $reflection->getName(), $reflection->getStartLine() !== false ? $reflection->getStartLine() : null];
338+
return [[$filename], $reflection->getName(), $reflection->getStartLine() !== false ? $reflection->getStartLine() : null];
327339
}
328340

329341
if (!$this->disableRuntimeReflectionProvider) {
@@ -333,8 +345,8 @@ private function locateClassByName(string $className): ?array
333345
$this->silenceErrors();
334346

335347
try {
336-
/** @var array{string, string, null}|null */
337-
return FileReadTrapStreamWrapper::withStreamWrapperOverride(
348+
/** @var array{string[], string, null}|null */
349+
$result = FileReadTrapStreamWrapper::withStreamWrapperOverride(
338350
static function () use ($className): ?array {
339351
$functions = spl_autoload_functions();
340352
if ($functions === false) {
@@ -350,14 +362,23 @@ static function () use ($className): ?array {
350362
*
351363
* This will not be `null` when the autoloader tried to read a file.
352364
*/
353-
if (FileReadTrapStreamWrapper::$autoloadLocatedFile !== null) {
354-
return [FileReadTrapStreamWrapper::$autoloadLocatedFile, $className, null];
365+
if (FileReadTrapStreamWrapper::$autoloadLocatedFiles !== []) {
366+
return [FileReadTrapStreamWrapper::$autoloadLocatedFiles, $className, null];
355367
}
356368
}
357369

358370
return null;
359371
},
360372
);
373+
if ($result === null) {
374+
return null;
375+
}
376+
377+
foreach ($result[0] as $file) {
378+
opcache_invalidate($file, true);
379+
}
380+
381+
return $result;
361382
} finally {
362383
restore_error_handler();
363384
}

src/Reflection/BetterReflection/SourceLocator/FileReadTrapStreamWrapper.php

+7-8
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ final class FileReadTrapStreamWrapper
3434
/** @var string[]|null */
3535
private static ?array $registeredStreamWrapperProtocols;
3636

37-
public static ?string $autoloadLocatedFile = null;
37+
/** @var string[] */
38+
public static array $autoloadLocatedFiles = [];
3839

3940
private bool $readFromFile = false;
4041

@@ -55,7 +56,7 @@ public static function withStreamWrapperOverride(
5556
)
5657
{
5758
self::$registeredStreamWrapperProtocols = $streamWrapperProtocols;
58-
self::$autoloadLocatedFile = null;
59+
self::$autoloadLocatedFiles = [];
5960

6061
try {
6162
foreach ($streamWrapperProtocols as $protocol) {
@@ -71,7 +72,7 @@ public static function withStreamWrapperOverride(
7172
}
7273

7374
self::$registeredStreamWrapperProtocols = null;
74-
self::$autoloadLocatedFile = null;
75+
self::$autoloadLocatedFiles = [];
7576

7677
return $result;
7778
}
@@ -93,9 +94,7 @@ public static function withStreamWrapperOverride(
9394
*/
9495
public function stream_open($path, $mode, $options, &$openedPath): bool
9596
{
96-
if (self::$autoloadLocatedFile === null) {
97-
self::$autoloadLocatedFile = $path;
98-
}
97+
self::$autoloadLocatedFiles[] = $path;
9998
$this->readFromFile = false;
10099
$this->seekPosition = 0;
101100

@@ -139,11 +138,11 @@ public function stream_close(): void
139138
*/
140139
public function stream_stat()
141140
{
142-
if (self::$autoloadLocatedFile === null) {
141+
if (self::$autoloadLocatedFiles === []) {
143142
return false;
144143
}
145144

146-
return $this->url_stat(self::$autoloadLocatedFile, STREAM_URL_STAT_QUIET);
145+
return $this->url_stat(self::$autoloadLocatedFiles[0], STREAM_URL_STAT_QUIET);
147146
}
148147

149148
/**

0 commit comments

Comments
 (0)