]> git.mxchange.org Git - friendica.git/blobdiff - src/Core/Config/Model/Config.php
Merge pull request #12674 from nupplaphil/bug/config_typesafe
[friendica.git] / src / Core / Config / Model / Config.php
index 593ab04070f032628f9041b8c545c9fba1aead0b..46d5643b344bc66e4538b693b17bc400bcba296f 100644 (file)
@@ -39,19 +39,32 @@ class Config implements IManageConfigValues
        /** @var ConfigFileManager */
        protected $configFileManager;
 
-       /** @var array */
-       protected $server;
-
        /**
         * @param ConfigFileManager $configFileManager The configuration file manager to save back configs
         * @param Cache             $configCache       The configuration cache (based on the config-files)
-        * @param array             $server            The $_SERVER variable
         */
-       public function __construct(ConfigFileManager $configFileManager, Cache $configCache, array $server = [])
+       public function __construct(ConfigFileManager $configFileManager, Cache $configCache)
        {
                $this->configFileManager = $configFileManager;
                $this->configCache       = $configCache;
-               $this->server            = $server;
+       }
+
+       /**
+        * 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();
        }
 
        /**
@@ -76,6 +89,8 @@ class Config implements IManageConfigValues
        {
                try {
                        $this->configFileManager->saveData($this->configCache);
+                       // reload after the save to possible reload default values of lower source-priorities again
+                       $this->reload();
                } catch (ConfigFileException $e) {
                        throw new ConfigPersistenceException('Cannot save config', $e);
                }
@@ -87,20 +102,13 @@ class Config implements IManageConfigValues
                $configCache = new Cache();
 
                try {
-                       $this->configFileManager->setupCache($configCache, $this->server);
+                       $this->configFileManager->setupCache($configCache);
                } catch (ConfigFileException $e) {
                        throw new ConfigPersistenceException('Cannot reload config', $e);
                }
                $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)
        {