Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit eacb74c

Browse files
alamiraultnicolas-grekas
authored andcommitted
[Config] Allow custom meta location in ConfigCache
1 parent 87186b2 commit eacb74c

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

src/Symfony/Component/Config/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
---
66

77
* Allow custom meta location in `ResourceCheckerConfigCache`
8+
* Allow custom meta location in `ConfigCache`
89

910
7.0
1011
---

src/Symfony/Component/Config/ConfigCache.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,21 @@
2626
class ConfigCache extends ResourceCheckerConfigCache
2727
{
2828
/**
29-
* @param string $file The absolute cache path
30-
* @param bool $debug Whether debugging is enabled or not
29+
* @param string $file The absolute cache path
30+
* @param bool $debug Whether debugging is enabled or not
31+
* @param string|null $metaFile The absolute path to the meta file
3132
*/
3233
public function __construct(
3334
string $file,
3435
private bool $debug,
36+
?string $metaFile = null,
3537
) {
3638
$checkers = [];
3739
if (true === $this->debug) {
3840
$checkers = [new SelfCheckingResourceChecker()];
3941
}
4042

41-
parent::__construct($file, $checkers);
43+
parent::__construct($file, $checkers, $metaFile);
4244
}
4345

4446
/**

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

+14-1
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,24 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Config\ConfigCache;
16+
use Symfony\Component\Config\Resource\FileResource;
1617
use Symfony\Component\Config\Resource\SelfCheckingResourceChecker;
1718
use Symfony\Component\Config\Tests\Resource\ResourceStub;
1819

1920
class ConfigCacheTest extends TestCase
2021
{
2122
private string $cacheFile;
23+
private string $metaFile;
2224

2325
protected function setUp(): void
2426
{
2527
$this->cacheFile = tempnam(sys_get_temp_dir(), 'config_');
28+
$this->metaFile = tempnam(sys_get_temp_dir(), 'config_');
2629
}
2730

2831
protected function tearDown(): void
2932
{
30-
$files = [$this->cacheFile, $this->cacheFile.'.meta'];
33+
$files = [$this->cacheFile, $this->cacheFile.'.meta', $this->metaFile];
3134

3235
foreach ($files as $file) {
3336
if (file_exists($file)) {
@@ -103,4 +106,14 @@ public static function debugModes(): array
103106
[false],
104107
];
105108
}
109+
110+
public function testCacheWithCustomMetaFile()
111+
{
112+
$this->assertStringEqualsFile($this->metaFile, '');
113+
114+
$cache = new ConfigCache($this->cacheFile, false, $this->metaFile);
115+
$cache->write('foo', [new FileResource(__FILE__)]);
116+
117+
$this->assertStringNotEqualsFile($this->metaFile, '');
118+
}
106119
}

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

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
class ResourceCheckerConfigCacheTest extends TestCase
2121
{
2222
private string $cacheFile;
23-
2423
private string $metaFile;
2524

2625
protected function setUp(): void

0 commit comments

Comments
 (0)