X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/2ab9e4acd3a2ceb5ff871b6b6afc786377e8739f..433017b9907c8348a48ef1a9fa7669e3d9523f1b:/lib/lib.php diff --git a/lib/lib.php b/lib/lib.php index c4fbca30..b4c415d9 100644 --- a/lib/lib.php +++ b/lib/lib.php @@ -1,5 +1,50 @@ load(CONST_DataDir.'/settings/env.defaults'); + + if (file_exists($sProjectDir.'/.env')) { + $dotenv->load($sProjectDir.'/.env'); + } +} + +function getSetting($sConfName, $sDefault = null) +{ + $sValue = $_SERVER['NOMINATIM_'.$sConfName]; + + if ($sDefault !== null && !$sValue) { + return $sDefault; + } + + return $sValue; +} + +function getSettingBool($sConfName) +{ + $sVal = strtolower(getSetting($sConfName)); + + return strcmp($sVal, 'yes') == 0 + || strcmp($sVal, 'true') == 0 + || strcmp($sVal, '1') == 0; +} + +function getSettingConfig($sConfName, $sSystemConfig) +{ + $sValue = $_ENV['NOMINATIM_'.$sConfName]; + + if (!$sValue) { + return CONST_DataDir.'/settings/'.$sSystemConfig; + } + + return $sValue; +} + function fail($sError, $sUserError = false) { if (!$sUserError) $sUserError = $sError; @@ -55,7 +100,7 @@ function byImportance($a, $b) if ($a['importance'] != $b['importance']) return ($a['importance'] > $b['importance']?-1:1); - return ($a['foundorder'] < $b['foundorder']?-1:1); + return $a['foundorder'] <=> $b['foundorder']; } @@ -89,6 +134,24 @@ function addQuotes($s) return "'".$s."'"; } +function fwriteConstDef($rFile, $sConstName, $value) +{ + $sEscapedValue; + + if (is_bool($value)) { + $sEscapedValue = $value ? 'true' : 'false'; + } elseif (is_numeric($value)) { + $sEscapedValue = strval($value); + } elseif (!$value) { + $sEscapedValue = 'false'; + } else { + $sEscapedValue = addQuotes(str_replace("'", "\\'", (string)$value)); + } + + fwrite($rFile, "@define('CONST_$sConstName', $sEscapedValue);\n"); +} + + function parseLatLon($sQuery) { $sFound = null;