Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions src/Discovery/Cache/SnapshotClassFinderComputedCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()}.
Expand Down Expand Up @@ -79,8 +80,11 @@ 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
Expand All @@ -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,
];
Expand All @@ -101,21 +105,29 @@ private function entries(
}

if ($entry['matching']) {
$result[$filename] = $entry['data'];
$result[$normalizedFilename] = $entry['data'];
}

$entries[$filename] = $entry;
$entries[$normalizedFilename] = $entry;

return false;
});

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

$result[$filename] = $map($classReflection);
$entries[$filename] = [
// Skip internal classes or classes without a file
if ($filename === false) {
continue;
}

// 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,
];

Expand Down
Loading