]> git.openstreetmap.org Git - nominatim.git/blobdiff - lib/lib.php
Merge pull request #2135 from lonvia/python-frontend
[nominatim.git] / lib / lib.php
index 753159d235690f6974a0d23e0502f1b0c792036a..7760f695304748fe80d9a549c5d76fedbdf5066a 100644 (file)
@@ -1,26 +1,44 @@
 <?php
 
-require('Symfony/Component/Dotenv/autoload.php');
-
 function loadSettings($sProjectDir)
 {
-    if (!$sProjectDir) {
-        $sProjectDir = getcwd();
-    }
-
     @define('CONST_InstallDir', $sProjectDir);
+    // Temporary hack to set the direcory via environment instead of
+    // the installed scripts. Neither setting is part of the official
+    // set of settings.
+    defined('CONST_DataDir') or define('CONST_DataDir', $_SERVER['NOMINATIM_DATADIR']);
+    defined('CONST_BinDir') or define('CONST_BinDir', $_SERVER['NOMINATIM_BINDIR']);
+}
 
-    $dotenv = new \Symfony\Component\Dotenv\Dotenv();
+function getSetting($sConfName, $sDefault = null)
+{
+    $sValue = $_SERVER['NOMINATIM_'.$sConfName];
 
-    if (file_exists($sProjectDir.'/.env')) {
-        $dotenv->load($sProjectDir.'/.env');
+    if ($sDefault !== null && !$sValue) {
+        return $sDefault;
     }
-    $dotenv->load(CONST_DataDir.'/settings/env.defaults');
+
+    return $sValue;
+}
+
+function getSettingBool($sConfName)
+{
+    $sVal = strtolower(getSetting($sConfName));
+
+    return strcmp($sVal, 'yes') == 0
+           || strcmp($sVal, 'true') == 0
+           || strcmp($sVal, '1') == 0;
 }
 
-function getSetting($sConfName)
+function getSettingConfig($sConfName, $sSystemConfig)
 {
-    return $_ENV['NOMINATIM_'.$sConfName];
+    $sValue = $_SERVER['NOMINATIM_'.$sConfName];
+
+    if (!$sValue) {
+        return CONST_DataDir.'/settings/'.$sSystemConfig;
+    }
+
+    return $sValue;
 }
 
 function fail($sError, $sUserError = false)
@@ -112,6 +130,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;