From a7cf0d976d3f15e7a1a31ab3f2b7cd646378b0ef Mon Sep 17 00:00:00 2001 From: Raymond Chong Date: Mon, 17 Nov 2025 12:14:31 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=F0=9F=90=9B=20fix(cache):=20Normalize=20fi?= =?UTF-8?q?le=20names=20to=20avoid=20Windows=20issues?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * In `SnapshotClassFinderComputedCache`, normalize file names to ensure no path issues occur in Windows environments. --- .../SnapshotClassFinderComputedCache.php | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/Discovery/Cache/SnapshotClassFinderComputedCache.php b/src/Discovery/Cache/SnapshotClassFinderComputedCache.php index 46a80b48d0..50515ae5a4 100644 --- a/src/Discovery/Cache/SnapshotClassFinderComputedCache.php +++ b/src/Discovery/Cache/SnapshotClassFinderComputedCache.php @@ -79,8 +79,12 @@ private function entries( $changed = false; $classFinder = $classFinder->withPathFilter(static function (string $filename) use (&$entries, &$result, &$changed, $previousEntries) { + + // Normalize filename to avoid issues on Windows. + $normalizedFilename = str_replace('\\', '/', $filename); + /** @var array{ data: TEntry, dependencies: FilesSnapshot, matching: bool } $entry */ - $entry = $previousEntries[$filename] ?? null; + $entry = $previousEntries[$normalizedFilename] ?? null; // If there's no entry in cache for this filename (new file or previously uncached), // or if it the file has been modified since caching, we'll try to autoload @@ -90,7 +94,7 @@ private function entries( // it will not be emitted in the iterator and won't reach the `foreach()` below. // So to avoid iterating over these files again, we'll mark them as non-matching. // If they are matching, it'll be overwritten in the `foreach` loop below. - $entries[$filename] = [ + $entries[$normalizedFilename] = [ 'dependencies' => FilesSnapshot::for([$filename]), 'matching' => false, ]; @@ -101,10 +105,10 @@ private function entries( } if ($entry['matching']) { - $result[$filename] = $entry['data']; + $result[$normalizedFilename] = $entry['data']; } - $entries[$filename] = $entry; + $entries[$normalizedFilename] = $entry; return false; }); @@ -112,10 +116,14 @@ private function entries( foreach ($classFinder as $classReflection) { $filename = $classReflection->getFileName(); - $result[$filename] = $map($classReflection); - $entries[$filename] = [ + // Normalize filename to avoid issues on Windows. + $normalizedFilename = str_replace('\\', '/', $filename); + + + $result[$normalizedFilename] = $map($classReflection); + $entries[$normalizedFilename] = [ 'dependencies' => FilesSnapshot::forClass($classReflection, true), - 'data' => $result[$filename], + 'data' => $result[$normalizedFilename], 'matching' => true, ]; From 8f692a664e7f0ad6cda214ff580638e4ebd5fb88 Mon Sep 17 00:00:00 2001 From: Raymond Chong Date: Tue, 18 Nov 2025 09:52:29 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=90=9B=20fix(cache):=20=E8=B7=B3?= =?UTF-8?q?=E9=81=8E=E5=85=A7=E9=83=A8=E9=A1=9E=E5=88=A5=E6=88=96=E6=B2=92?= =?UTF-8?q?=E6=9C=89=E6=AA=94=E6=A1=88=E7=9A=84=E9=A1=9E=E5=88=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 在 `SnapshotClassFinderComputedCache` 中新增檢查,以跳過內部類別或沒有檔案的類別。 * 確保在 Windows 環境下正常化檔案名稱,避免潛在的問題。 --- src/Discovery/Cache/SnapshotClassFinderComputedCache.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Discovery/Cache/SnapshotClassFinderComputedCache.php b/src/Discovery/Cache/SnapshotClassFinderComputedCache.php index 50515ae5a4..d3afa1cbe2 100644 --- a/src/Discovery/Cache/SnapshotClassFinderComputedCache.php +++ b/src/Discovery/Cache/SnapshotClassFinderComputedCache.php @@ -116,6 +116,11 @@ private function entries( foreach ($classFinder as $classReflection) { $filename = $classReflection->getFileName(); + // Skip internal classes or classes without a file + if ($filename === false) { + continue; + } + // Normalize filename to avoid issues on Windows. $normalizedFilename = str_replace('\\', '/', $filename); From 1900f2d6ff4ef6b7838c4a07b26af19699efd21c Mon Sep 17 00:00:00 2001 From: Raymond Chong Date: Tue, 18 Nov 2025 10:07:21 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=F0=9F=90=9B=20fix(cache):=20=E6=AD=A3?= =?UTF-8?q?=E8=A6=8F=E5=8C=96=E6=AA=94=E6=A1=88=E5=90=8D=E7=A8=B1=E4=BB=A5?= =?UTF-8?q?=E9=81=BF=E5=85=8D=20Windows=20=E5=95=8F=E9=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 在 `SnapshotClassFinderComputedCache` 類別中,對檔案名稱進行正規化處理。 * 這樣可以避免在 Windows 環境下出現的路徑問題。 --- src/Discovery/Cache/SnapshotClassFinderComputedCache.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Discovery/Cache/SnapshotClassFinderComputedCache.php b/src/Discovery/Cache/SnapshotClassFinderComputedCache.php index d3afa1cbe2..dd04e7547b 100644 --- a/src/Discovery/Cache/SnapshotClassFinderComputedCache.php +++ b/src/Discovery/Cache/SnapshotClassFinderComputedCache.php @@ -79,7 +79,6 @@ private function entries( $changed = false; $classFinder = $classFinder->withPathFilter(static function (string $filename) use (&$entries, &$result, &$changed, $previousEntries) { - // Normalize filename to avoid issues on Windows. $normalizedFilename = str_replace('\\', '/', $filename); @@ -124,7 +123,6 @@ private function entries( // Normalize filename to avoid issues on Windows. $normalizedFilename = str_replace('\\', '/', $filename); - $result[$normalizedFilename] = $map($classReflection); $entries[$normalizedFilename] = [ 'dependencies' => FilesSnapshot::forClass($classReflection, true), From 07e46f78a2f95c5e5017de4be042cd3b6ce977b6 Mon Sep 17 00:00:00 2001 From: Raymond Chong Date: Tue, 18 Nov 2025 10:13:21 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E2=9C=A8=20feat(cache):=20=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=20`str=5Freplace`=20=E5=87=BD=E6=95=B8=E7=9A=84?= =?UTF-8?q?=E5=BC=95=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Discovery/Cache/SnapshotClassFinderComputedCache.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Discovery/Cache/SnapshotClassFinderComputedCache.php b/src/Discovery/Cache/SnapshotClassFinderComputedCache.php index dd04e7547b..df94c06545 100644 --- a/src/Discovery/Cache/SnapshotClassFinderComputedCache.php +++ b/src/Discovery/Cache/SnapshotClassFinderComputedCache.php @@ -10,6 +10,7 @@ use TheCodingMachine\GraphQLite\Discovery\ClassFinder; use function sprintf; +use function str_replace; /** * Provides cache for a {@see ClassFinder} based on a {@see filemtime()}.