renamed Logger::setLogger() to Logger::init()

This commit is contained in:
Philipp Holzer 2019-02-11 21:36:26 +01:00
parent 80f1feabe5
commit e1d9d67632
No known key found for this signature in database
GPG key ID: 517BE60E2CE5C8A5
12 changed files with 276 additions and 92 deletions

View file

@ -29,8 +29,7 @@ interface IConfigAdapter
public function get($cat, $key);
/**
* Stores a config value ($value) in the category ($family) under the key ($key)
* for the user_id $uid.
* Stores a config value ($value) in the category ($family) under the key ($key).
*
* Note: Please do not store booleans - convert to 0/1 integer values!
*
@ -59,4 +58,14 @@ interface IConfigAdapter
* @return bool
*/
public function isConnected();
/**
* Checks, if a config value ($value) in the category ($cat) is already loaded.
*
* @param string $cat The configuration category
* @param string $key The configuration key
*
* @return bool
*/
public function isLoaded($cat, $key);
}

View file

@ -69,4 +69,15 @@ interface IPConfigAdapter
* @return bool
*/
public function isConnected();
/**
* Checks, if a config value ($value) in the category ($cat) is already loaded for the user_id $uid.
*
* @param string $uid The user_id
* @param string $cat The configuration category
* @param string $key The configuration key
*
* @return bool
*/
public function isLoaded($uid, $cat, $key);
}

View file

@ -120,4 +120,16 @@ class JITConfigAdapter extends AbstractDbaConfigAdapter implements IConfigAdapte
return $result;
}
/**
* {@inheritdoc}
*/
public function isLoaded($cat, $key)
{
if (!$this->isConnected()) {
return false;
}
return (isset($this->in_db[$cat][$key])) && $this->in_db[$cat][$key];
}
}

View file

@ -36,7 +36,7 @@ class JITPConfigAdapter extends AbstractDbaConfigAdapter implements IPConfigAdap
}
} else if ($cat != 'config') {
// Negative caching
$return[null] = "!<unset>!";
$return = "!<unset>!";
}
DBA::close($pconfigs);
@ -123,4 +123,16 @@ class JITPConfigAdapter extends AbstractDbaConfigAdapter implements IPConfigAdap
return $result;
}
/**
* {@inheritdoc}
*/
public function isLoaded($uid, $cat, $key)
{
if (!$this->isConnected()) {
return false;
}
return (isset($this->in_db[$uid][$cat][$key])) && $this->in_db[$uid][$cat][$key];
}
}

View file

@ -32,13 +32,13 @@ class PreloadConfigAdapter extends AbstractDbaConfigAdapter implements IConfigAd
$configs = DBA::select('config', ['cat', 'v', 'k']);
while ($config = DBA::fetch($configs)) {
$return[$config['k']] = $config['v'];
$return[$config['cat']][$config['k']] = $config['v'];
}
DBA::close($configs);
$this->config_loaded = true;
return [$cat => $return];
return $return;
}
/**
@ -101,4 +101,16 @@ class PreloadConfigAdapter extends AbstractDbaConfigAdapter implements IConfigAd
return $result;
}
/**
* {@inheritdoc}
*/
public function isLoaded($cat, $key)
{
if (!$this->isConnected()) {
return false;
}
return $this->config_loaded;
}
}

View file

@ -44,13 +44,13 @@ class PreloadPConfigAdapter extends AbstractDbaConfigAdapter implements IPConfig
$pconfigs = DBA::select('pconfig', ['cat', 'v', 'k'], ['uid' => $uid]);
while ($pconfig = DBA::fetch($pconfigs)) {
$return[$pconfig['k']] = $pconfig['v'];
$return[$pconfig['cat']][$pconfig['k']] = $pconfig['v'];
}
DBA::close($pconfigs);
$this->config_loaded = true;
return [$cat => $return];
return $return;
}
/**
@ -123,4 +123,16 @@ class PreloadPConfigAdapter extends AbstractDbaConfigAdapter implements IPConfig
return $result;
}
/**
* {@inheritdoc}
*/
public function isLoaded($uid, $cat, $key)
{
if (!$this->isConnected()) {
return false;
}
return $this->config_loaded;
}
}

View file

@ -79,22 +79,20 @@ class Configuration
*/
public function get($cat, $key, $default_value = null, $refresh = false)
{
// Return the value of the cache if found and no refresh is forced
if (!$refresh && $this->configCache->has($cat, $key)) {
// if the value isn't loaded or refresh is needed, load it to the cache
if ($this->configAdapter->isConnected() &&
(!$this->configAdapter->isLoaded($cat, $key) ||
$refresh)) {
$dbvalue = $this->configAdapter->get($cat, $key);
if ($dbvalue !== '!<unset>!') {
$this->configCache->set($cat, $key, $dbvalue);
}
}
// use the config cache for return
if ($this->configCache->has($cat, $key)) {
return $this->configCache->get($cat, $key);
}
// if we don't find the value in the cache and the adapter isn't ready, return the default value
if (!$this->configAdapter->isConnected()) {
return $default_value;
}
// load DB value to cache
$dbvalue = $this->configAdapter->get($cat, $key);
if ($dbvalue !== '!<unset>!') {
$this->configCache->set($cat, $key, $dbvalue);
return $dbvalue;
} else {
return $default_value;
}

View file

@ -71,22 +71,20 @@ class PConfiguration
*/
public function get($uid, $cat, $key, $default_value = null, $refresh = false)
{
// Return the value of the cache if found and no refresh is forced
if (!$refresh && $this->configCache->hasP($uid, $cat, $key)) {
// if the value isn't loaded or refresh is needed, load it to the cache
if ($this->configAdapter->isConnected() &&
(!$this->configAdapter->isLoaded($uid, $cat, $key) ||
$refresh)) {
$dbValue = $this->configAdapter->get($uid, $cat, $key);
if ($dbValue !== '!<unset>!') {
$this->configCache->setP($uid, $cat, $key, $dbValue);
}
}
// use the config cache for return
if ($this->configCache->hasP($uid, $cat, $key)) {
return $this->configCache->getP($uid, $cat, $key);
}
// if we don't find the value in the cache and the adapter isn't ready, return the default value
if (!$this->configAdapter->isConnected()) {
return $default_value;
}
// load DB value to cache
$dbvalue = $this->configAdapter->get($uid, $cat, $key);
if ($dbvalue !== '!<unset>!') {
$this->configCache->setP($uid, $cat, $key, $dbvalue);
return $dbvalue;
} else {
return $default_value;
}

View file

@ -68,7 +68,7 @@ class Logger extends BaseObject
*
* @param LoggerInterface $logger The Logger instance of this Application
*/
public static function setLogger($logger)
public static function init($logger)
{
self::$logger = $logger;
}

View file

@ -44,7 +44,7 @@ class LoggerFactory
static::addStreamHandler($logger, $stream, $loglevel);
}
Logger::setLogger($logger);
Logger::init($logger);
return $logger;
}