mirror of
https://git.friendi.ca/friendica/friendica.git
synced 2025-06-12 02:44:26 +02:00
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:
parent
2d91d5c3d9
commit
8c3aebc376
24 changed files with 175 additions and 157 deletions
|
@ -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] = [];
|
||||
}
|
||||
|
|
|
@ -37,9 +37,6 @@ class ConfigCacheLoader
|
|||
*/
|
||||
public function loadConfigFiles(ConfigCache $config)
|
||||
{
|
||||
// Setting at least the basepath we know
|
||||
$config->set('system', 'basepath', $this->baseDir);
|
||||
|
||||
$config->load($this->loadCoreConfig('defaults'));
|
||||
$config->load($this->loadCoreConfig('settings'));
|
||||
|
||||
|
|
|
@ -20,9 +20,9 @@ interface IConfigCache
|
|||
* Gets a value from the config cache.
|
||||
*
|
||||
* @param string $cat Config category
|
||||
* @param string $key Config key
|
||||
* @param string $key Config key
|
||||
*
|
||||
* @return mixed Returns the value of the Config entry or '!<unset>!' if not set
|
||||
* @return null|mixed Returns the value of the Config entry or null if not set
|
||||
*/
|
||||
function get($cat, $key = null);
|
||||
|
||||
|
@ -47,15 +47,6 @@ interface IConfigCache
|
|||
*/
|
||||
function delete($cat, $key);
|
||||
|
||||
/**
|
||||
* Checks if a value is set in the config cache.
|
||||
*
|
||||
* @param string $cat Config category
|
||||
* @param string $key Config key
|
||||
* @return bool
|
||||
*/
|
||||
function has($cat, $key = null);
|
||||
|
||||
/**
|
||||
* Returns the whole configuration cache
|
||||
*
|
||||
|
|
|
@ -23,7 +23,7 @@ interface IPConfigCache
|
|||
* @param string $cat Config category
|
||||
* @param string $key Config key
|
||||
*
|
||||
* @return string The value of the config entry or '!<unset>!' if not set
|
||||
* @return null|string The value of the config entry or null if not set
|
||||
*/
|
||||
function getP($uid, $cat, $key = null);
|
||||
|
||||
|
@ -50,17 +50,6 @@ interface IPConfigCache
|
|||
*/
|
||||
function deleteP($uid, $cat, $key);
|
||||
|
||||
|
||||
/**
|
||||
* Checks if a value is set in the user config cache.
|
||||
*
|
||||
* @param int $uid User Id
|
||||
* @param string $cat Config category
|
||||
* @param string $key Config key
|
||||
* @return bool
|
||||
*/
|
||||
function hasP($uid, $cat, $key = null);
|
||||
|
||||
/**
|
||||
* Returns the whole configuration cache
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue