]> git.mxchange.org Git - friendica.git/blobdiff - src/Core/Config/Cache/ConfigCache.php
Merge branch 'master' into develop
[friendica.git] / src / Core / Config / Cache / ConfigCache.php
index cb299eb330956624e41eff564a074bd3973b0ed2..441cdee811cc550c3e0bb748c8fdb26887b0dc59 100644 (file)
@@ -2,10 +2,12 @@
 
 namespace Friendica\Core\Config\Cache;
 
+use ParagonIE\HiddenString\HiddenString;
+
 /**
  * The Friendica config cache for the application
  * Initial, all *.config.php files are loaded into this cache with the
- * ConfigCacheLoader ( @see ConfigCacheLoader )
+ * ConfigFileLoader ( @see ConfigFileLoader )
  */
 class ConfigCache implements IConfigCache, IPConfigCache
 {
@@ -14,11 +16,18 @@ class ConfigCache implements IConfigCache, IPConfigCache
         */
        private $config;
 
+       /**
+        * @var bool
+        */
+       private $hidePasswordOutput;
+
        /**
         * @param array $config    A initial config array
+        * @param bool  $hidePasswordOutput True, if cache variables should take extra care of password values
         */
-       public function __construct(array $config = [])
+       public function __construct(array $config = [], $hidePasswordOutput = true)
        {
+               $this->hidePasswordOutput = $hidePasswordOutput;
                $this->load($config);
        }
 
@@ -84,8 +93,13 @@ class ConfigCache implements IConfigCache, IPConfigCache
                        $this->config[$cat] = [];
                }
 
-               $this->config[$cat][$key] = $value;
-
+               if ($this->hidePasswordOutput &&
+                   $key == 'password' &&
+                   !empty($value) && is_string($value)) {
+                       $this->config[$cat][$key] = new HiddenString((string) $value);
+               } else {
+                       $this->config[$cat][$key] = $value;
+               }
                return true;
        }
 
@@ -188,4 +202,32 @@ class ConfigCache implements IConfigCache, IPConfigCache
        {
                return $this->config;
        }
+
+       /**
+        * Returns an array with missing categories/Keys
+        *
+        * @param array $config The array to check
+        *
+        * @return array
+        */
+       public function keyDiff(array $config)
+       {
+               $return = [];
+
+               $categories = array_keys($config);
+
+               foreach ($categories as $category) {
+                       if (is_array($config[$category])) {
+                               $keys = array_keys($config[$category]);
+
+                               foreach ($keys as $key) {
+                                       if (!isset($this->config[$category][$key])) {
+                                               $return[$category][$key] = $config[$category][$key];
+                                       }
+                               }
+                       }
+               }
+
+               return $return;
+       }
 }