Skip to content

Commit a7cf0d9

Browse files
committed
🐛 fix(cache): Normalize file names to avoid Windows issues
* In `SnapshotClassFinderComputedCache`, normalize file names to ensure no path issues occur in Windows environments.
1 parent cb7c195 commit a7cf0d9

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/Discovery/Cache/SnapshotClassFinderComputedCache.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,12 @@ private function entries(
7979
$changed = false;
8080

8181
$classFinder = $classFinder->withPathFilter(static function (string $filename) use (&$entries, &$result, &$changed, $previousEntries) {
82+
83+
// Normalize filename to avoid issues on Windows.
84+
$normalizedFilename = str_replace('\\', '/', $filename);
85+
8286
/** @var array{ data: TEntry, dependencies: FilesSnapshot, matching: bool } $entry */
83-
$entry = $previousEntries[$filename] ?? null;
87+
$entry = $previousEntries[$normalizedFilename] ?? null;
8488

8589
// If there's no entry in cache for this filename (new file or previously uncached),
8690
// or if it the file has been modified since caching, we'll try to autoload
@@ -90,7 +94,7 @@ private function entries(
9094
// it will not be emitted in the iterator and won't reach the `foreach()` below.
9195
// So to avoid iterating over these files again, we'll mark them as non-matching.
9296
// If they are matching, it'll be overwritten in the `foreach` loop below.
93-
$entries[$filename] = [
97+
$entries[$normalizedFilename] = [
9498
'dependencies' => FilesSnapshot::for([$filename]),
9599
'matching' => false,
96100
];
@@ -101,21 +105,25 @@ private function entries(
101105
}
102106

103107
if ($entry['matching']) {
104-
$result[$filename] = $entry['data'];
108+
$result[$normalizedFilename] = $entry['data'];
105109
}
106110

107-
$entries[$filename] = $entry;
111+
$entries[$normalizedFilename] = $entry;
108112

109113
return false;
110114
});
111115

112116
foreach ($classFinder as $classReflection) {
113117
$filename = $classReflection->getFileName();
114118

115-
$result[$filename] = $map($classReflection);
116-
$entries[$filename] = [
119+
// Normalize filename to avoid issues on Windows.
120+
$normalizedFilename = str_replace('\\', '/', $filename);
121+
122+
123+
$result[$normalizedFilename] = $map($classReflection);
124+
$entries[$normalizedFilename] = [
117125
'dependencies' => FilesSnapshot::forClass($classReflection, true),
118-
'data' => $result[$filename],
126+
'data' => $result[$normalizedFilename],
119127
'matching' => true,
120128
];
121129

0 commit comments

Comments
 (0)