Bugfixings in Config

- replaced usage of "!<unset>!" with null-returns
- fixed bool settings (0/1)
- fixed overriding config-values
- fixed basepath problems
This commit is contained in:
Philipp Holzer 2019-02-22 23:51:13 +01:00
parent 2d91d5c3d9
commit 8c3aebc376
No known key found for this signature in database
GPG key ID: 517BE60E2CE5C8A5
24 changed files with 175 additions and 157 deletions

View file

@ -6,8 +6,6 @@ namespace Friendica\Core\Config\Cache;
* 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 )
*/
class ConfigCache implements IConfigCache, IPConfigCache
{
@ -37,7 +35,7 @@ class ConfigCache implements IConfigCache, IPConfigCache
foreach ($keys as $key) {
$value = $config[$category][$key];
if (isset($value) && $value !== '!<unset>!') {
if (isset($value)) {
if ($overwrite) {
$this->set($category, $key, $value);
} else {
@ -56,22 +54,13 @@ class ConfigCache implements IConfigCache, IPConfigCache
{
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.
*
@ -91,9 +80,6 @@ class ConfigCache implements IConfigCache, IPConfigCache
*/
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] = [];
}
@ -103,15 +89,6 @@ class ConfigCache implements IConfigCache, IPConfigCache
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}
*/
@ -142,7 +119,7 @@ class ConfigCache implements IConfigCache, IPConfigCache
foreach ($keys as $key) {
$value = $config[$category][$key];
if (isset($value) && $value !== '!<unset>!') {
if (isset($value)) {
$this->setP($uid, $category, $key, $value);
}
}
@ -157,10 +134,10 @@ class ConfigCache implements IConfigCache, IPConfigCache
{
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;
}
}
@ -169,9 +146,6 @@ class ConfigCache implements IConfigCache, IPConfigCache
*/
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] = [];
}