From fef10e8a57984a90a164102583a42de351502df8 Mon Sep 17 00:00:00 2001 From: Philipp Date: Wed, 11 Jan 2023 22:00:29 +0100 Subject: [PATCH] Improve encapsulation --- .../Config/Capability/IManageConfigValues.php | 14 ----------- src/Core/Config/Model/Config.php | 25 +++++++++++++------ src/Core/Config/Model/ConfigTransaction.php | 4 +-- src/Core/Config/ValueObject/Cache.php | 2 +- 4 files changed, 21 insertions(+), 24 deletions(-) diff --git a/src/Core/Config/Capability/IManageConfigValues.php b/src/Core/Config/Capability/IManageConfigValues.php index 09e2cd914..2c3d6da3c 100644 --- a/src/Core/Config/Capability/IManageConfigValues.php +++ b/src/Core/Config/Capability/IManageConfigValues.php @@ -58,20 +58,6 @@ interface IManageConfigValues */ public function get(string $cat, string $key = null, $default_value = null); - /** - * Load all configuration values from a given cache and saves it back in the configuration node store - * @see ConfigFileManager::CONFIG_DATA_FILE - * - * All configuration values of the system are stored in the cache. - * - * @param Cache $cache a new cache - * - * @return void - * - * @throws ConfigPersistenceException In case the persistence layer throws errors - */ - public function load(Cache $cache); - /** * Sets a configuration value for system config * diff --git a/src/Core/Config/Model/Config.php b/src/Core/Config/Model/Config.php index 5258033a7..46d5643b3 100644 --- a/src/Core/Config/Model/Config.php +++ b/src/Core/Config/Model/Config.php @@ -49,6 +49,24 @@ class Config implements IManageConfigValues $this->configCache = $configCache; } + /** + * Load all configuration values from a given cache and saves it back in the configuration node store + * @see ConfigFileManager::CONFIG_DATA_FILE + * + * All configuration values of the system are stored in the cache. + * + * @param Cache $cache a new cache + * + * @return void + * + * @throws ConfigPersistenceException In case the persistence layer throws errors + */ + public function setCacheAndSave(Cache $cache) + { + $this->configCache = $cache; + $this->save(); + } + /** * {@inheritDoc} */ @@ -91,13 +109,6 @@ class Config implements IManageConfigValues $this->configCache = $configCache; } - /** {@inheritDoc} */ - public function load(Cache $cache) - { - $this->configCache = $cache; - $this->save(); - } - /** {@inheritDoc} */ public function get(string $cat, string $key = null, $default_value = null) { diff --git a/src/Core/Config/Model/ConfigTransaction.php b/src/Core/Config/Model/ConfigTransaction.php index ec0a2b9c8..b9310301f 100644 --- a/src/Core/Config/Model/ConfigTransaction.php +++ b/src/Core/Config/Model/ConfigTransaction.php @@ -57,7 +57,7 @@ class ConfigTransaction implements ISetConfigValuesTransactionally /** {@inheritDoc} */ public function delete(string $cat, string $key): ISetConfigValuesTransactionally { - $this->cache->delete($cat, $key, Cache::SOURCE_DATA); + $this->cache->delete($cat, $key); $this->changedConfig = true; return $this; @@ -72,7 +72,7 @@ class ConfigTransaction implements ISetConfigValuesTransactionally } try { - $this->config->load($this->cache); + $this->config->setCacheAndSave($this->cache); $this->cache = clone $this->config->getCache(); } catch (\Exception $e) { throw new ConfigPersistenceException('Cannot save config', $e); diff --git a/src/Core/Config/ValueObject/Cache.php b/src/Core/Config/ValueObject/Cache.php index be42ae118..acfac3ab9 100644 --- a/src/Core/Config/ValueObject/Cache.php +++ b/src/Core/Config/ValueObject/Cache.php @@ -56,7 +56,7 @@ class Cache private $source = []; /** - * @var array + * @var bool[][] */ private $delConfig = [];