Skip to content

Commit 3c02748

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 c9e7809 commit 3c02748

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+
7.1
5+
---
6+
7+
* Added method `getMeta()` to ResourceCheckerConfigCache and ConfigCacheInterface
8+
49
7.0
510
---
611

src/Symfony/Component/Config/ConfigCacheInterface.php

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

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;
@@ -133,6 +127,22 @@ public function write(string $content, array $metadata = null): void
133127
}
134128
}
135129

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

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)