diff options
Diffstat (limited to 'modules-available/baseconfig/inc/baseconfig.inc.php')
-rw-r--r-- | modules-available/baseconfig/inc/baseconfig.inc.php | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/modules-available/baseconfig/inc/baseconfig.inc.php b/modules-available/baseconfig/inc/baseconfig.inc.php index 064e0f89..36622dce 100644 --- a/modules-available/baseconfig/inc/baseconfig.inc.php +++ b/modules-available/baseconfig/inc/baseconfig.inc.php @@ -17,13 +17,15 @@ class BaseConfig */ public static function prepareFromRequest() { - $ip = $_SERVER['REMOTE_ADDR']; + $ip = $_SERVER['REMOTE_ADDR'] ?? null; + if ($ip === null) + ErrorHandler::traceError('No REMOTE_ADDR given in $_SERVER'); if (substr($ip, 0, 7) === '::ffff:') { $ip = substr($ip, 7); } - $uuid = Request::any('uuid', false, 'string'); - if ($uuid !== false && strlen($uuid) !== 36) { - $uuid = false; + $uuid = Request::any('uuid', null, 'string'); + if ($uuid !== null && strlen($uuid) !== 36) { + $uuid = null; } // Handle any hooks by other modules first // other modules should generally only populate $configVars @@ -42,10 +44,10 @@ class BaseConfig * 'locationid' * @param array $overrides key value pairs of overrides */ - public static function prepareWithOverrides($overrides) + public static function prepareWithOverrides(array $overrides): void { self::$overrides = $overrides; - $ip = $uuid = false; + $ip = $uuid = null; if (self::hasOverride('ip')) { $ip = self::getOverride('ip'); } @@ -78,12 +80,12 @@ class BaseConfig // Dump global config from DB ConfigHolder::setContext('<global>', function($id) { return [ - 'name' => Dictionary::translate('source-global', true), + 'name' => Dictionary::translate('source-global'), 'locationid' => 0, ]; }); $res = Database::simpleQuery('SELECT setting, value, displayvalue FROM setting_global'); - while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + foreach ($res as $row) { if (!isset($defaults[$row['setting']])) continue; // Setting is not defined in any <module>/baseconfig/settings.json ConfigHolder::add($row['setting'], $row, -1); @@ -98,7 +100,7 @@ class BaseConfig { ConfigHolder::setContext('<default>', function($id) { return [ - 'name' => Dictionary::translate('source-default', true), + 'name' => Dictionary::translate('source-default'), 'locationid' => 0, ]; }); @@ -107,8 +109,9 @@ class BaseConfig } } - private static function handleModule($name, $ip, $uuid, $needJsonHook) // Pass ip and uuid instead of global to make them read only + private static function handleModule(string $name, ?string $ip, ?string $uuid, bool $needJsonHook): void { + // Pass ip and uuid instead of global to make them read only if (isset(self::$modulesDone[$name])) return; self::$modulesDone[$name] = true; @@ -130,12 +133,12 @@ class BaseConfig self::handleModule($dep, $ip, $uuid, $needJsonHook); } ConfigHolder::setContext($name); - (function ($file, $ip, $uuid) { + (function (string $file, ?string $ip, ?string $uuid) { include_once($file); })($file, $ip, $uuid); } - public static function hasOverride($key) + public static function hasOverride($key): bool { return array_key_exists($key, self::$overrides); } |