$section) { foreach ($section as $key => $value) { self::setConfig($header, $key, $value); } } foreach ($customConfig as $header => $section) { foreach ($section as $key => $value) { self::setConfig($header, $key, $value); } } foreach ($env as $envName => $envValue) { $nameParts = explode('_', $envName); if ($nameParts[0] === 'RSSBRIDGE') { $header = $nameParts[1]; $key = $nameParts[2]; if ($envValue === 'true' || $envValue === 'false') { $envValue = filter_var($envValue, FILTER_VALIDATE_BOOLEAN); } self::setConfig($header, $key, $envValue); } } if ( !is_string(self::getConfig('system', 'timezone')) || !in_array(self::getConfig('system', 'timezone'), timezone_identifiers_list(DateTimeZone::ALL_WITH_BC)) ) { self::throwConfigError('system', 'timezone'); } if (!is_string(self::getConfig('proxy', 'url'))) { self::throwConfigError('proxy', 'url', 'Is not a valid string'); } if (!is_bool(self::getConfig('proxy', 'by_bridge'))) { self::throwConfigError('proxy', 'by_bridge', 'Is not a valid Boolean'); } if (!is_string(self::getConfig('proxy', 'name'))) { /** Name of the proxy server */ self::throwConfigError('proxy', 'name', 'Is not a valid string'); } if (!is_string(self::getConfig('cache', 'type'))) { self::throwConfigError('cache', 'type', 'Is not a valid string'); } if (!is_bool(self::getConfig('cache', 'custom_timeout'))) { self::throwConfigError('cache', 'custom_timeout', 'Is not a valid Boolean'); } if (!is_bool(self::getConfig('authentication', 'enable'))) { self::throwConfigError('authentication', 'enable', 'Is not a valid Boolean'); } if (!is_string(self::getConfig('authentication', 'username'))) { self::throwConfigError('authentication', 'username', 'Is not a valid string'); } if (!is_string(self::getConfig('authentication', 'password'))) { self::throwConfigError('authentication', 'password', 'Is not a valid string'); } if ( !empty(self::getConfig('admin', 'email')) && !filter_var(self::getConfig('admin', 'email'), FILTER_VALIDATE_EMAIL) ) { self::throwConfigError('admin', 'email', 'Is not a valid email address'); } if (!is_bool(self::getConfig('admin', 'donations'))) { self::throwConfigError('admin', 'donations', 'Is not a valid Boolean'); } if (!is_string(self::getConfig('error', 'output'))) { self::throwConfigError('error', 'output', 'Is not a valid String'); } if ( !is_numeric(self::getConfig('error', 'report_limit')) || self::getConfig('error', 'report_limit') < 1 ) { self::throwConfigError('admin', 'report_limit', 'Value is invalid'); } } public static function getConfig(string $section, string $key) { return self::$config[strtolower($section)][strtolower($key)] ?? null; } private static function setConfig(string $section, string $key, $value): void { self::$config[strtolower($section)][strtolower($key)] = $value; } public static function getVersion() { $headFile = __DIR__ . '/../.git/HEAD'; if (@is_readable($headFile)) { $revisionHashFile = '.git/' . substr(file_get_contents($headFile), 5, -1); $parts = explode('/', $revisionHashFile); if (isset($parts[3])) { $branchName = $parts[3]; if (file_exists($revisionHashFile)) { return 'git.' . $branchName . '.' . substr(file_get_contents($revisionHashFile), 0, 7); } } } return self::VERSION; } private static function throwConfigError($section, $key, $message = '') { throw new \Exception("Config [$section] => [$key] is invalid. $message"); } }