diff --git a/src/Symfony/Component/Config/CHANGELOG.md b/src/Symfony/Component/Config/CHANGELOG.md index 51e2d1fee567b..e2607f4687d99 100644 --- a/src/Symfony/Component/Config/CHANGELOG.md +++ b/src/Symfony/Component/Config/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +7.1 +--- + + * Added method `getMeta()` to ResourceCheckerConfigCache and ConfigCacheInterface + 7.0 --- diff --git a/src/Symfony/Component/Config/ConfigCacheInterface.php b/src/Symfony/Component/Config/ConfigCacheInterface.php index f3ea53bde64da..558bceba1d4b5 100644 --- a/src/Symfony/Component/Config/ConfigCacheInterface.php +++ b/src/Symfony/Component/Config/ConfigCacheInterface.php @@ -42,4 +42,11 @@ public function isFresh(): bool; * @throws \RuntimeException When the cache file cannot be written */ public function write(string $content, array $metadata = null): void; + + /* + * Returns the metadata stored for this cache. + * + * @return false|ResourceInterface[] + */ + // public function getMeta() : false | array; } diff --git a/src/Symfony/Component/Config/ResourceCheckerConfigCache.php b/src/Symfony/Component/Config/ResourceCheckerConfigCache.php index 6816e477731bd..7c25cd0d46b1d 100644 --- a/src/Symfony/Component/Config/ResourceCheckerConfigCache.php +++ b/src/Symfony/Component/Config/ResourceCheckerConfigCache.php @@ -68,13 +68,7 @@ public function isFresh(): bool return true; // shortcut - if we don't have any checkers we don't need to bother with the meta file at all } - $metadata = $this->getMetaFile(); - - if (!is_file($metadata)) { - return false; - } - - $meta = $this->safelyUnserialize($metadata); + $meta = $this->getMeta(); if (false === $meta) { return false; @@ -133,6 +127,22 @@ public function write(string $content, array $metadata = null): void } } + /** + * Returns the metadata stored for this cache. + * + * @return false|ResourceInterface[] + */ + public function getMeta(): false|array + { + $metadata = $this->getMetaFile(); + + if (!is_file($metadata)) { + return false; + } + + return $this->safelyUnserialize($metadata); + } + /** * Gets the meta file path. */ diff --git a/src/Symfony/Component/Config/Tests/ResourceCheckerConfigCacheTest.php b/src/Symfony/Component/Config/Tests/ResourceCheckerConfigCacheTest.php index 37f30a49d4ec0..975ce00843e91 100644 --- a/src/Symfony/Component/Config/Tests/ResourceCheckerConfigCacheTest.php +++ b/src/Symfony/Component/Config/Tests/ResourceCheckerConfigCacheTest.php @@ -148,4 +148,14 @@ public function testCacheIsNotFreshIfNotExistsMetaFile() $this->assertFalse($cache->isFresh()); } + + public function testGetMeta() + { + $checker = $this->createMock(ResourceCheckerInterface::class); + $cache = new ResourceCheckerConfigCache($this->cacheFile, [$checker]); + $cache->write('foo', [new FileResource(__FILE__)]); + + $this->assertCount(1, $cache->getMeta()); + $this->assertEquals(new FileResource(__FILE__), $cache->getMeta()[0]); + } }