Skip to content

Commit 87e083f

Browse files
committed
Expose meta on ResourceCheckerConfigCache / ConfigCacheInterface
When a developer adds meta to a config cache, it should also be possible to get back the meta. I use these config caches for my own framework and want to retrieve a specific meta associated to the cache.
1 parent 7074da9 commit 87e083f

File tree

4 files changed

+39
-7
lines changed

4 files changed

+39
-7
lines changed

src/Symfony/Component/Config/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
6.4
5+
---
6+
7+
* Added method `getMeta()` to ResourceCheckerConfigCache and ConfigCacheInterface
8+
49
6.3
510
---
611

src/Symfony/Component/Config/ConfigCacheInterface.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,11 @@ public function isFresh(): bool;
4444
* @throws \RuntimeException When the cache file cannot be written
4545
*/
4646
public function write(string $content, array $metadata = null);
47+
48+
/**
49+
* Returns the metadata stored for this cache.
50+
*
51+
* @return ResourceInterface[]
52+
*/
53+
//public function getMeta() : false | array;
4754
}

src/Symfony/Component/Config/ResourceCheckerConfigCache.php

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,7 @@ public function isFresh(): bool
6868
return true; // shortcut - if we don't have any checkers we don't need to bother with the meta file at all
6969
}
7070

71-
$metadata = $this->getMetaFile();
72-
73-
if (!is_file($metadata)) {
74-
return false;
75-
}
76-
77-
$meta = $this->safelyUnserialize($metadata);
71+
$meta = $this->getMeta();
7872

7973
if (false === $meta) {
8074
return false;
@@ -135,6 +129,22 @@ public function write(string $content, array $metadata = null)
135129
}
136130
}
137131

132+
/**
133+
* Returns the metadata stored for this cache.
134+
*
135+
* @return ResourceInterface[]
136+
*/
137+
public function getMeta() : false | array
138+
{
139+
$metadata = $this->getMetaFile();
140+
141+
if (!is_file($metadata)) {
142+
return false;
143+
}
144+
145+
return $this->safelyUnserialize($metadata);
146+
}
147+
138148
/**
139149
* Gets the meta file path.
140150
*/

src/Symfony/Component/Config/Tests/ResourceCheckerConfigCacheTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,14 @@ public function testCacheIsNotFreshIfNotExistsMetaFile()
148148

149149
$this->assertFalse($cache->isFresh());
150150
}
151+
152+
public function testGetMeta()
153+
{
154+
$checker = $this->createMock(ResourceCheckerInterface::class);
155+
$cache = new ResourceCheckerConfigCache($this->cacheFile, [$checker]);
156+
$cache->write('foo', [new FileResource(__FILE__)]);
157+
158+
$this->assertCount(1, $cache->getMeta());
159+
$this->assertEquals(new FileResource(__FILE__), $cache->getMeta()[0]);
160+
}
151161
}

0 commit comments

Comments
 (0)