]> git.mxchange.org Git - friendica.git/blobdiff - src/Core/Config/PreloadPConfigAdapter.php
Merge pull request #6593 from tobiasd/20190206-can
[friendica.git] / src / Core / Config / PreloadPConfigAdapter.php
index ed18bdf2e7dc01e7fa9c05aac4db0698b76ceda0..af97815adef38d159ab6ba44f27766d10ed7ca9d 100644 (file)
@@ -20,20 +20,23 @@ class PreloadPConfigAdapter implements IPConfigAdapter
         * The config cache of this adapter
         * @var IPConfigCache
         */
-       private $config;
+       private $configCache;
 
        /**
-        * @param IPConfigCache $config The config cache of this adapter
+        * @param IPConfigCache $configCache The config cache of this adapter
         * @param int           $uid    The UID of the current user
         */
-       public function __construct($config, $uid = null)
+       public function __construct(IPConfigCache $configCache, $uid = null)
        {
-               $this->config = $config;
+               $this->configCache = $configCache;
                if (isset($uid)) {
                        $this->load($uid, 'config');
                }
        }
 
+       /**
+        * {@inheritdoc}
+        */
        public function load($uid, $family)
        {
                if ($this->config_loaded) {
@@ -46,13 +49,16 @@ class PreloadPConfigAdapter implements IPConfigAdapter
 
                $pconfigs = DBA::select('pconfig', ['cat', 'v', 'k'], ['uid' => $uid]);
                while ($pconfig = DBA::fetch($pconfigs)) {
-                       $this->config->setP($uid, $pconfig['cat'], $pconfig['k'], $pconfig['v']);
+                       $this->configCache->setP($uid, $pconfig['cat'], $pconfig['k'], $pconfig['v']);
                }
                DBA::close($pconfigs);
 
                $this->config_loaded = true;
        }
 
+       /**
+        * {@inheritdoc}
+        */
        public function get($uid, $cat, $k, $default_value = null, $refresh = false)
        {
                if (!$this->config_loaded) {
@@ -62,15 +68,18 @@ class PreloadPConfigAdapter implements IPConfigAdapter
                if ($refresh) {
                        $config = DBA::selectFirst('pconfig', ['v'], ['uid' => $uid, 'cat' => $cat, 'k' => $k]);
                        if (DBA::isResult($config)) {
-                               $this->config->setP($uid, $cat, $k, $config['v']);
+                               $this->configCache->setP($uid, $cat, $k, $config['v']);
                        } else {
-                               $this->config->deleteP($uid, $cat, $k);
+                               $this->configCache->deleteP($uid, $cat, $k);
                        }
                }
 
-               return $this->config->getP($uid, $cat, $k, $default_value);;
+               return $this->configCache->getP($uid, $cat, $k, $default_value);;
        }
 
+       /**
+        * {@inheritdoc}
+        */
        public function set($uid, $cat, $k, $value)
        {
                if (!$this->config_loaded) {
@@ -81,11 +90,11 @@ class PreloadPConfigAdapter implements IPConfigAdapter
                // The exception are array values.
                $compare_value = !is_array($value) ? (string)$value : $value;
 
-               if ($this->config->getP($uid, $cat, $k) === $compare_value) {
+               if ($this->configCache->getP($uid, $cat, $k) === $compare_value) {
                        return true;
                }
 
-               $this->config->setP($uid, $cat, $k, $value);
+               $this->configCache->setP($uid, $cat, $k, $value);
 
                // manage array value
                $dbvalue = is_array($value) ? serialize($value) : $value;
@@ -98,13 +107,16 @@ class PreloadPConfigAdapter implements IPConfigAdapter
                return true;
        }
 
+       /**
+        * {@inheritdoc}
+        */
        public function delete($uid, $cat, $k)
        {
                if (!$this->config_loaded) {
                        $this->load($uid, $cat);
                }
 
-               $this->config->deleteP($uid, $cat, $k);
+               $this->configCache->deleteP($uid, $cat, $k);
 
                $result = DBA::delete('pconfig', ['uid' => $uid, 'cat' => $cat, 'k' => $k]);