Introduce ISetConfigValuesTransactional for transactional config behaviour

This commit is contained in:
Philipp 2023-01-03 14:18:53 +01:00
parent 4d4b4a8858
commit 65d79d4c93
No known key found for this signature in database
GPG key ID: 24A7501396EB5432
14 changed files with 588 additions and 150 deletions

View file

@ -279,4 +279,71 @@ class Cache
return $return;
}
/**
* Merges a new Cache into the existing one and returns the merged Cache
*
* @param Cache $cache The cache, which should get merged into this Cache
*
* @return Cache The merged Cache
*/
public function merge(Cache $cache): Cache
{
$newConfig = $this->config;
$newSource = $this->source;
$categories = array_keys($cache->config);
foreach ($categories as $category) {
if (is_array($cache->config[$category])) {
$keys = array_keys($cache->config[$category]);
foreach ($keys as $key) {
$newConfig[$category][$key] = $cache->config[$category][$key];
$newSource[$category][$key] = $cache->source[$category][$key];
}
}
}
$newCache = new Cache();
$newCache->config = $newConfig;
$newCache->source = $newSource;
return $newCache;
}
/**
* Diffs a new Cache into the existing one and returns the diffed Cache
*
* @param Cache $cache The cache, which should get deleted for the current Cache
*
* @return Cache The diffed Cache
*/
public function diff(Cache $cache): Cache
{
$newConfig = $this->config;
$newSource = $this->source;
$categories = array_keys($cache->config);
foreach ($categories as $category) {
if (is_array($cache->config[$category])) {
$keys = array_keys($cache->config[$category]);
foreach ($keys as $key) {
if (!is_null($newConfig[$category][$key] ?? null)) {
unset($newConfig[$category][$key]);
unset($newSource[$category][$key]);
}
}
}
}
$newCache = new Cache();
$newCache->config = $newConfig;
$newCache->source = $newSource;
return $newCache;
}
}