|
10 | 10 | use PHPStan\Command\Output;
|
11 | 11 | use PHPStan\Dependency\ExportedNodeFetcher;
|
12 | 12 | use PHPStan\Dependency\RootExportedNode;
|
| 13 | +use PHPStan\DependencyInjection\Container; |
13 | 14 | use PHPStan\DependencyInjection\ProjectConfigHelper;
|
14 | 15 | use PHPStan\File\CouldNotReadFileException;
|
15 | 16 | use PHPStan\File\FileFinder;
|
@@ -66,6 +67,7 @@ final class ResultCacheManager
|
66 | 67 | * @param string[] $scanDirectories
|
67 | 68 | */
|
68 | 69 | public function __construct(
|
| 70 | + private Container $container, |
69 | 71 | private ExportedNodeFetcher $exportedNodeFetcher,
|
70 | 72 | private FileFinder $scanFileFinder,
|
71 | 73 | private ReflectionProvider $reflectionProvider,
|
@@ -317,6 +319,11 @@ private function isMetaDifferent(array $cachedMeta, array $currentMeta): bool
|
317 | 319 | $currentMeta['projectConfig'] = Neon::encode($currentMeta['projectConfig']);
|
318 | 320 | }
|
319 | 321 |
|
| 322 | + // Do not invalidate result cache generated before introducing support for result cache meta extensions |
| 323 | + if (!isset($currentMeta['phpstanExtensions'])) { |
| 324 | + $currentMeta['phpstanExtensions'] = []; |
| 325 | + } |
| 326 | + |
320 | 327 | return $cachedMeta !== $currentMeta;
|
321 | 328 | }
|
322 | 329 |
|
@@ -904,6 +911,7 @@ private function getMeta(array $allAnalysedFiles, ?array $projectConfigArray): a
|
904 | 911 | return [
|
905 | 912 | 'cacheVersion' => self::CACHE_VERSION,
|
906 | 913 | 'phpstanVersion' => ComposerHelper::getPhpStanVersion(),
|
| 914 | + 'phpstanExtensions' => $this->getMetaFromPhpStanExtensions(), |
907 | 915 | 'phpVersion' => PHP_VERSION_ID,
|
908 | 916 | 'projectConfig' => $projectConfigArray,
|
909 | 917 | 'analysedPaths' => $this->analysedPaths,
|
@@ -1036,4 +1044,27 @@ private function getStubFiles(): array
|
1036 | 1044 | return $stubFiles;
|
1037 | 1045 | }
|
1038 | 1046 |
|
| 1047 | + /** |
| 1048 | + * @return array<string, string> |
| 1049 | + * @throws ShouldNotHappenException |
| 1050 | + */ |
| 1051 | + private function getMetaFromPhpStanExtensions(): array |
| 1052 | + { |
| 1053 | + $meta = []; |
| 1054 | + |
| 1055 | + /** @var ResultCacheMetaExtension $extension */ |
| 1056 | + foreach ($this->container->getServicesByTag(ResultCacheMetaExtension::EXTENSION_TAG) as $extension) { |
| 1057 | + if (array_key_exists($extension->getKey(), $meta)) { |
| 1058 | + throw new ShouldNotHappenException(sprintf( |
| 1059 | + 'Duplicate ResultCacheMetaExtension with key "%s" found.', |
| 1060 | + $extension->getKey(), |
| 1061 | + )); |
| 1062 | + } |
| 1063 | + |
| 1064 | + $meta[$extension->getKey()] = $extension->getHash(); |
| 1065 | + } |
| 1066 | + |
| 1067 | + return $meta; |
| 1068 | + } |
| 1069 | + |
1039 | 1070 | }
|
0 commit comments