diff --git a/src/Symfony/Component/Config/CHANGELOG.md b/src/Symfony/Component/Config/CHANGELOG.md index 79709aaa78f85..1697989556fd0 100644 --- a/src/Symfony/Component/Config/CHANGELOG.md +++ b/src/Symfony/Component/Config/CHANGELOG.md @@ -5,6 +5,7 @@ CHANGELOG --- * Allow custom meta location in `ResourceCheckerConfigCache` + * Allow custom meta location in `ConfigCache` 7.0 --- diff --git a/src/Symfony/Component/Config/ConfigCache.php b/src/Symfony/Component/Config/ConfigCache.php index 1fea03a823875..7c87b9b9e682d 100644 --- a/src/Symfony/Component/Config/ConfigCache.php +++ b/src/Symfony/Component/Config/ConfigCache.php @@ -26,19 +26,21 @@ class ConfigCache extends ResourceCheckerConfigCache { /** - * @param string $file The absolute cache path - * @param bool $debug Whether debugging is enabled or not + * @param string $file The absolute cache path + * @param bool $debug Whether debugging is enabled or not + * @param string|null $metaFile The absolute path to the meta file */ public function __construct( string $file, private bool $debug, + ?string $metaFile = null, ) { $checkers = []; if (true === $this->debug) { $checkers = [new SelfCheckingResourceChecker()]; } - parent::__construct($file, $checkers); + parent::__construct($file, $checkers, $metaFile); } /** diff --git a/src/Symfony/Component/Config/Tests/ConfigCacheTest.php b/src/Symfony/Component/Config/Tests/ConfigCacheTest.php index f4ead1d528d88..e639fb220ef8f 100644 --- a/src/Symfony/Component/Config/Tests/ConfigCacheTest.php +++ b/src/Symfony/Component/Config/Tests/ConfigCacheTest.php @@ -13,21 +13,24 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\Config\ConfigCache; +use Symfony\Component\Config\Resource\FileResource; use Symfony\Component\Config\Resource\SelfCheckingResourceChecker; use Symfony\Component\Config\Tests\Resource\ResourceStub; class ConfigCacheTest extends TestCase { private string $cacheFile; + private string $metaFile; protected function setUp(): void { $this->cacheFile = tempnam(sys_get_temp_dir(), 'config_'); + $this->metaFile = tempnam(sys_get_temp_dir(), 'config_'); } protected function tearDown(): void { - $files = [$this->cacheFile, $this->cacheFile.'.meta']; + $files = [$this->cacheFile, $this->cacheFile.'.meta', $this->metaFile]; foreach ($files as $file) { if (file_exists($file)) { @@ -103,4 +106,14 @@ public static function debugModes(): array [false], ]; } + + public function testCacheWithCustomMetaFile() + { + $this->assertStringEqualsFile($this->metaFile, ''); + + $cache = new ConfigCache($this->cacheFile, false, $this->metaFile); + $cache->write('foo', [new FileResource(__FILE__)]); + + $this->assertStringNotEqualsFile($this->metaFile, ''); + } } diff --git a/src/Symfony/Component/Config/Tests/ResourceCheckerConfigCacheTest.php b/src/Symfony/Component/Config/Tests/ResourceCheckerConfigCacheTest.php index 53b66b88e447f..2415e419a7208 100644 --- a/src/Symfony/Component/Config/Tests/ResourceCheckerConfigCacheTest.php +++ b/src/Symfony/Component/Config/Tests/ResourceCheckerConfigCacheTest.php @@ -20,7 +20,6 @@ class ResourceCheckerConfigCacheTest extends TestCase { private string $cacheFile; - private string $metaFile; protected function setUp(): void