Skip to content

Commit 6bd0985

Browse files
committed
Updated Rector to commit 4a6cb199966a4c12d7178921f4ce36df607e9d17
rectorphp/rector-src@4a6cb19 [Caching] Add CacheMetaExtensionInterface for custom cache invalidation (#7933)
1 parent f2a28a0 commit 6bd0985

8 files changed

Lines changed: 80 additions & 3 deletions

File tree

src/Application/VersionResolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ final class VersionResolver
1919
* @api
2020
* @var string
2121
*/
22-
public const PACKAGE_VERSION = 'f7b87f33d7f109a18f8d6a2ce7080e9fb10ba92d';
22+
public const PACKAGE_VERSION = '4a6cb199966a4c12d7178921f4ce36df607e9d17';
2323
/**
2424
* @api
2525
* @var string
2626
*/
27-
public const RELEASE_DATE = '2026-03-27 11:19:24';
27+
public const RELEASE_DATE = '2026-03-27 12:04:27';
2828
/**
2929
* @var int
3030
*/

src/Caching/Config/FileHashComputer.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,40 @@
44
namespace Rector\Caching\Config;
55

66
use Rector\Application\VersionResolver;
7+
use Rector\Caching\Contract\CacheMetaExtensionInterface;
78
use Rector\Configuration\Parameter\SimpleParameterProvider;
89
use Rector\Exception\ShouldNotHappenException;
910
/**
1011
* Inspired by https://github.com/symplify/easy-coding-standard/blob/e598ab54686e416788f28fcfe007fd08e0f371d9/packages/changed-files-detector/src/FileHashComputer.php
1112
*/
1213
final class FileHashComputer
1314
{
15+
/**
16+
* @var CacheMetaExtensionInterface[]
17+
* @readonly
18+
*/
19+
private array $cacheMetaExtensions = [];
20+
/**
21+
* @param CacheMetaExtensionInterface[] $cacheMetaExtensions
22+
*/
23+
public function __construct(array $cacheMetaExtensions = [])
24+
{
25+
$this->cacheMetaExtensions = $cacheMetaExtensions;
26+
}
1427
public function compute(string $filePath): string
1528
{
1629
$this->ensureIsPhp($filePath);
1730
$parametersHash = SimpleParameterProvider::hash();
18-
return sha1($filePath . $parametersHash . VersionResolver::PACKAGE_VERSION);
31+
$extensionHash = $this->computeExtensionHash();
32+
return sha1($filePath . $parametersHash . $extensionHash . VersionResolver::PACKAGE_VERSION);
33+
}
34+
private function computeExtensionHash(): string
35+
{
36+
$extensionHash = '';
37+
foreach ($this->cacheMetaExtensions as $cacheMetaExtension) {
38+
$extensionHash .= $cacheMetaExtension->getKey() . ':' . $cacheMetaExtension->getHash();
39+
}
40+
return $extensionHash;
1941
}
2042
private function ensureIsPhp(string $filePath): void
2143
{
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
declare (strict_types=1);
4+
namespace Rector\Caching\Contract;
5+
6+
/**
7+
* Allows extensions to provide additional metadata for cache invalidation.
8+
* When any extension's hash changes, all cached files are reprocessed.
9+
*
10+
* @api
11+
*/
12+
interface CacheMetaExtensionInterface
13+
{
14+
/**
15+
* Returns unique key for this cache meta entry.
16+
* This describes the source of the metadata.
17+
*/
18+
public function getKey(): string;
19+
/**
20+
* Returns hash of the cache meta entry.
21+
* This represents the current state of the additional meta source.
22+
*/
23+
public function getHash(): string;
24+
}

src/Config/RectorConfig.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
use RectorPrefix202603\Illuminate\Container\Container;
77
use Override;
8+
use Rector\Caching\Contract\CacheMetaExtensionInterface;
89
use Rector\Caching\Contract\ValueObject\Storage\CacheStorageInterface;
910
use Rector\Configuration\Option;
1011
use Rector\Configuration\Parameter\SimpleParameterProvider;
@@ -284,6 +285,15 @@ public function cacheClass(string $cacheClass): void
284285
Assert::isAOf($cacheClass, CacheStorageInterface::class);
285286
SimpleParameterProvider::setParameter(Option::CACHE_CLASS, $cacheClass);
286287
}
288+
/**
289+
* @param class-string<CacheMetaExtensionInterface> $cacheMetaExtensionClass
290+
*/
291+
public function cacheMetaExtension(string $cacheMetaExtensionClass): void
292+
{
293+
Assert::isAOf($cacheMetaExtensionClass, CacheMetaExtensionInterface::class);
294+
$this->singleton($cacheMetaExtensionClass);
295+
$this->tag($cacheMetaExtensionClass, CacheMetaExtensionInterface::class);
296+
}
287297
/**
288298
* @see https://github.com/nikic/PHP-Parser/issues/723#issuecomment-712401963
289299
*/

src/Configuration/RectorConfigBuilder.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use PhpParser\NodeVisitor;
77
use Rector\Bridge\SetProviderCollector;
88
use Rector\Bridge\SetRectorsResolver;
9+
use Rector\Caching\Contract\CacheMetaExtensionInterface;
910
use Rector\Caching\Contract\ValueObject\Storage\CacheStorageInterface;
1011
use Rector\Composer\InstalledPackageResolver;
1112
use Rector\Config\Level\CodeQualityLevel;
@@ -82,6 +83,10 @@ final class RectorConfigBuilder
8283
private ?string $cacheClass = null;
8384
private ?string $cacheDirectory = null;
8485
private ?string $containerCacheDirectory = null;
86+
/**
87+
* @var array<class-string<CacheMetaExtensionInterface>>
88+
*/
89+
private array $cacheMetaExtensions = [];
8590
private ?bool $parallel = null;
8691
private int $parallelTimeoutSeconds = 120;
8792
private int $parallelMaxNumberOfProcess = Defaults::PARALLEL_MAX_NUMBER_OF_PROCESS;
@@ -222,6 +227,9 @@ public function __invoke(RectorConfig $rectorConfig): void
222227
if ($this->containerCacheDirectory !== null) {
223228
$rectorConfig->containerCacheDirectory($this->containerCacheDirectory);
224229
}
230+
foreach ($this->cacheMetaExtensions as $cacheMetaExtensionClass) {
231+
$rectorConfig->cacheMetaExtension($cacheMetaExtensionClass);
232+
}
225233
if ($this->importNames || $this->importDocBlockNames) {
226234
$rectorConfig->importNames($this->importNames, $this->importDocBlockNames);
227235
$rectorConfig->importShortClasses($this->importShortClasses);
@@ -605,6 +613,14 @@ public function withCache(?string $cacheDirectory = null, ?string $cacheClass =
605613
$this->containerCacheDirectory = $containerCacheDirectory;
606614
return $this;
607615
}
616+
/**
617+
* @param class-string<CacheMetaExtensionInterface> $cacheMetaExtensionClass
618+
*/
619+
public function withCacheMetaExtension(string $cacheMetaExtensionClass): self
620+
{
621+
$this->cacheMetaExtensions[] = $cacheMetaExtensionClass;
622+
return $this;
623+
}
608624
/**
609625
* @param class-string<ConfigurableRectorInterface> $rectorClass
610626
* @param mixed[] $configuration

src/DependencyInjection/LazyContainerFactory.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
use Rector\BetterPhpDocParser\PhpDocParser\StaticDoctrineAnnotationParser\PlainValueParser;
3636
use Rector\Caching\Cache;
3737
use Rector\Caching\CacheFactory;
38+
use Rector\Caching\Config\FileHashComputer;
39+
use Rector\Caching\Contract\CacheMetaExtensionInterface;
3840
use Rector\ChangesReporting\Contract\Output\OutputFormatterInterface;
3941
use Rector\ChangesReporting\Output\ConsoleOutputFormatter;
4042
use Rector\ChangesReporting\Output\GitHubOutputFormatter;
@@ -296,6 +298,7 @@ public function create(): RectorConfig
296298
$cacheFactory = $container->make(CacheFactory::class);
297299
return $cacheFactory->create();
298300
});
301+
$rectorConfig->when(FileHashComputer::class)->needs('$cacheMetaExtensions')->giveTagged(CacheMetaExtensionInterface::class);
299302
// tagged services
300303
$rectorConfig->when(BetterPhpDocParser::class)->needs('$phpDocNodeDecorators')->giveTagged(PhpDocNodeDecoratorInterface::class);
301304
$rectorConfig->afterResolving(ArrayTypeMapper::class, static function (ArrayTypeMapper $arrayTypeMapper, Container $container): void {

vendor/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,7 @@
11371137
'Rector\\Caching\\Cache' => $baseDir . '/src/Caching/Cache.php',
11381138
'Rector\\Caching\\CacheFactory' => $baseDir . '/src/Caching/CacheFactory.php',
11391139
'Rector\\Caching\\Config\\FileHashComputer' => $baseDir . '/src/Caching/Config/FileHashComputer.php',
1140+
'Rector\\Caching\\Contract\\CacheMetaExtensionInterface' => $baseDir . '/src/Caching/Contract/CacheMetaExtensionInterface.php',
11401141
'Rector\\Caching\\Contract\\ValueObject\\Storage\\CacheStorageInterface' => $baseDir . '/src/Caching/Contract/ValueObject/Storage/CacheStorageInterface.php',
11411142
'Rector\\Caching\\Detector\\ChangedFilesDetector' => $baseDir . '/src/Caching/Detector/ChangedFilesDetector.php',
11421143
'Rector\\Caching\\Enum\\CacheKey' => $baseDir . '/src/Caching/Enum/CacheKey.php',

vendor/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,6 +1397,7 @@ class ComposerStaticInitc9819cb6f85619d8e1cbb4426044dd33
13971397
'Rector\\Caching\\Cache' => __DIR__ . '/../..' . '/src/Caching/Cache.php',
13981398
'Rector\\Caching\\CacheFactory' => __DIR__ . '/../..' . '/src/Caching/CacheFactory.php',
13991399
'Rector\\Caching\\Config\\FileHashComputer' => __DIR__ . '/../..' . '/src/Caching/Config/FileHashComputer.php',
1400+
'Rector\\Caching\\Contract\\CacheMetaExtensionInterface' => __DIR__ . '/../..' . '/src/Caching/Contract/CacheMetaExtensionInterface.php',
14001401
'Rector\\Caching\\Contract\\ValueObject\\Storage\\CacheStorageInterface' => __DIR__ . '/../..' . '/src/Caching/Contract/ValueObject/Storage/CacheStorageInterface.php',
14011402
'Rector\\Caching\\Detector\\ChangedFilesDetector' => __DIR__ . '/../..' . '/src/Caching/Detector/ChangedFilesDetector.php',
14021403
'Rector\\Caching\\Enum\\CacheKey' => __DIR__ . '/../..' . '/src/Caching/Enum/CacheKey.php',

0 commit comments

Comments
 (0)