Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Config] Expose meta on ResourceCheckerConfigCache and ConfigCacheInterface #52059

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

Open
wants to merge 1 commit into
base: 7.4
Choose a base branch
Loading
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
  • Loading branch information
ruudk committed Nov 16, 2023
commit 3c02748311ef63084d2d84a2cc1b7ccdb70b44cb
5 changes: 5 additions & 0 deletions 5 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 7 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 24 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]);
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.