Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Config] Expose meta on ResourceCheckerConfigCache and ConfigCacheInterface #52059

Open
wants to merge 1 commit into
base: 7.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Symfony/Component/Config/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

7.1
---

* Added method `getMeta()` to ResourceCheckerConfigCache and ConfigCacheInterface

7.0
---

Expand Down
7 changes: 7 additions & 0 deletions src/Symfony/Component/Config/ConfigCacheInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
24 changes: 17 additions & 7 deletions src/Symfony/Component/Config/ResourceCheckerConfigCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
}