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
*/
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);
}
$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;
}
{
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;
+ }
}