/**
* The Friendica config cache for the application
* Initial, all *.config.php files are loaded into this cache with the
- * ConfigCacheLoader ( @see ConfigCacheLoader )
- *
- * Is used for further caching operations too (depending on the ConfigAdapter )
+ * ConfigFileLoader ( @see ConfigFileLoader )
*/
class ConfigCache implements IConfigCache, IPConfigCache
{
$categories = array_keys($config);
foreach ($categories as $category) {
- if (isset($config[$category]) && is_array($config[$category])) {
+ if (is_array($config[$category])) {
$keys = array_keys($config[$category]);
foreach ($keys as $key) {
- if (isset($config[$category][$key])) {
+ $value = $config[$category][$key];
+ if (isset($value)) {
if ($overwrite) {
- $this->set($category, $key, $config[$category][$key]);
+ $this->set($category, $key, $value);
} else {
- $this->setDefault($category, $key, $config[$category][$key]);
+ $this->setDefault($category, $key, $value);
}
}
}
{
if (isset($this->config[$cat][$key])) {
return $this->config[$cat][$key];
- } elseif ($key == null && isset($this->config[$cat])) {
+ } elseif (!isset($key) && isset($this->config[$cat])) {
return $this->config[$cat];
} else {
- return '!<unset>!';
+ return null;
}
}
- /**
- * {@inheritdoc}
- */
- public function has($cat, $key = null)
- {
- return (isset($this->config[$cat][$key]) && $this->config[$cat][$key] !== '!<unset>!') ||
- ($key == null && isset($this->config[$cat]) && $this->config[$cat] !== '!<unset>!' && is_array($this->config[$cat]));
- }
-
/**
* Sets a default value in the config cache. Ignores already existing keys.
*
*/
public function set($cat, $key, $value)
{
- // Only arrays are serialized in database, so we have to unserialize sparingly
- $value = is_string($value) && preg_match("|^a:[0-9]+:{.*}$|s", $value) ? unserialize($value) : $value;
-
if (!isset($this->config[$cat])) {
$this->config[$cat] = [];
}
return true;
}
- /**
- * {@inheritdoc}
- */
- public function hasP($uid, $cat, $key = null)
- {
- return (isset($this->config[$uid][$cat][$key]) && $this->config[$uid][$cat][$key] !== '!<unset>!') ||
- ($key == null && isset($this->config[$uid][$cat]) && $this->config[$uid][$cat] !== '!<unset>!' && is_array($this->config[$uid][$cat]));
- }
-
/**
* {@inheritdoc}
*/
*/
public function loadP($uid, array $config)
{
- foreach ($config as $category => $values) {
- foreach ($values as $key => $value) {
- $this->setP($uid, $category, $key, $value);
+ $categories = array_keys($config);
+
+ foreach ($categories as $category) {
+ if (isset($config[$category]) && is_array($config[$category])) {
+
+ $keys = array_keys($config[$category]);
+
+ foreach ($keys as $key) {
+ $value = $config[$category][$key];
+ if (isset($value)) {
+ $this->setP($uid, $category, $key, $value);
+ }
+ }
}
}
}
{
if (isset($this->config[$uid][$cat][$key])) {
return $this->config[$uid][$cat][$key];
- } elseif ($key == null && isset($this->config[$uid][$cat])) {
+ } elseif (!isset($key) && isset($this->config[$uid][$cat])) {
return $this->config[$uid][$cat];
} else {
- return '!<unset>!';
+ return null;
}
}
*/
public function setP($uid, $cat, $key, $value)
{
- // Only arrays are serialized in database, so we have to unserialize sparingly
- $value = is_string($value) && preg_match("|^a:[0-9]+:{.*}$|s", $value) ? unserialize($value) : $value;
-
if (!isset($this->config[$uid]) || !is_array($this->config[$uid])) {
$this->config[$uid] = [];
}
{
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;
+ }
}