refactor: use static values for cache scope

This fixes a future problem when code is placed under a namespace because `get_class($bridge)` will then return e.g. `RssBridge\Bridge\TwitterBridge` instead of the the current value `TwitterBridge`.

Also a bit refactoring of `Configuration.php`.
This commit is contained in:
Dag 2022-08-02 15:03:54 +02:00 committed by GitHub
parent a0a0d5235b
commit ecb486794b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 42 additions and 41 deletions

View file

@ -131,8 +131,8 @@ final class Configuration
self::reportError('The default configuration file is missing at ' . FILE_CONFIG_DEFAULT);
}
Configuration::$config = parse_ini_file(FILE_CONFIG_DEFAULT, true, INI_SCANNER_TYPED);
if (!Configuration::$config) {
$config = parse_ini_file(FILE_CONFIG_DEFAULT, true, INI_SCANNER_TYPED);
if (!$config) {
self::reportError('Error parsing ' . FILE_CONFIG_DEFAULT);
}
@ -140,24 +140,26 @@ final class Configuration
// Replace default configuration with custom settings
foreach (parse_ini_file(FILE_CONFIG, true, INI_SCANNER_TYPED) as $header => $section) {
foreach ($section as $key => $value) {
Configuration::$config[$header][$key] = $value;
$config[$header][$key] = $value;
}
}
}
foreach (getenv() as $envkey => $value) {
foreach (getenv() as $envName => $envValue) {
// Replace all settings with their respective environment variable if available
$keyArray = explode('_', $envkey);
$keyArray = explode('_', $envName);
if ($keyArray[0] === 'RSSBRIDGE') {
$header = strtolower($keyArray[1]);
$key = strtolower($keyArray[2]);
if ($value === 'true' || $value === 'false') {
$value = filter_var($value, FILTER_VALIDATE_BOOLEAN);
if ($envValue === 'true' || $envValue === 'false') {
$envValue = filter_var($envValue, FILTER_VALIDATE_BOOLEAN);
}
Configuration::$config[$header][$key] = $value;
$config[$header][$key] = $envValue;
}
}
self::$config = $config;
if (
!is_string(self::getConfig('system', 'timezone'))
|| !in_array(self::getConfig('system', 'timezone'), timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))
@ -165,14 +167,10 @@ final class Configuration
self::reportConfigurationError('system', 'timezone');
}
date_default_timezone_set(self::getConfig('system', 'timezone'));
if (!is_string(self::getConfig('proxy', 'url'))) {
/** URL of the proxy server */
self::reportConfigurationError('proxy', 'url', 'Is not a valid string');
}
/** True if proxy usage can be enabled selectively for each bridge */
if (!is_bool(self::getConfig('proxy', 'by_bridge'))) {
self::reportConfigurationError('proxy', 'by_bridge', 'Is not a valid Boolean');
}
@ -190,9 +188,6 @@ final class Configuration
self::reportConfigurationError('cache', 'custom_timeout', 'Is not a valid Boolean');
}
/** True if the cache timeout can be specified by the user */
define('CUSTOM_CACHE_TIMEOUT', self::getConfig('cache', 'custom_timeout'));
if (!is_bool(self::getConfig('authentication', 'enable'))) {
self::reportConfigurationError('authentication', 'enable', 'Is not a valid Boolean');
}