introduce dotenv parsing for setup.php

This adds the notion of a project directory. This is the directory
that holds all necessary files for one specific installation of
Nominatim. Dotenv looks for an .env file in this directory and
adds it to the global environment together with the defaults from
Nominatim's data directory.

Add's symfony's dotenv library as a new dependency.
This commit is contained in:
Sarah Hoffmann
2020-12-15 13:57:34 +01:00
parent ac116980ac
commit 25bdd7c6d9
3 changed files with 20 additions and 2 deletions

View File

@@ -3,7 +3,5 @@
@define('CONST_BinDir', '@CMAKE_SOURCE_DIR@/utils');
@define('CONST_LibDir', '@CMAKE_SOURCE_DIR@/lib');
@define('CONST_DataDir', '@CMAKE_SOURCE_DIR@');
@define('CONST_InstallDir', '@CMAKE_BINARY_DIR@');
require_once(CONST_InstallDir.'/settings/settings.php');
require_once(CONST_BinDir.'/@script_source@');

View File

@@ -1,5 +1,23 @@
<?php
require('Symfony/Component/Dotenv/autoload.php');
function loadSettings($sProjectDir)
{
if (!$sProjectDir) {
$sProjectDir = getcwd();
}
@define('CONST_InstallDir', $sProjectDir);
$dotenv = new \Symfony\Component\Dotenv\Dotenv();
if (file_exists($sProjectDir.'/.env')) {
$dotenv->load($sProjectDir.'/.env');
}
$dotenv->load(CONST_DataDir.'/settings/env.defaults');
}
function fail($sError, $sUserError = false)
{
if (!$sUserError) $sUserError = $sError;

View File

@@ -44,11 +44,13 @@ $aCMDOptions
array('create-country-names', '', 0, 1, 0, 0, 'bool', 'Create default list of searchable country names'),
array('drop', '', 0, 1, 0, 0, 'bool', 'Drop tables needed for updates, making the database readonly (EXPERIMENTAL)'),
array('setup-website', '', 0, 1, 0, 0, 'bool', 'Used to compile environment variables for the website'),
array('project-dir', '', 0, 1, 1, 1, 'realpath', 'Base directory for this Nominatim installation'),
);
// $aCMDOptions passed to getCmdOpt by reference
getCmdOpt($_SERVER['argv'], $aCMDOptions, $aCMDResult, true, true);
loadSettings($aCMDResult['project-dir'] ?? false);
setupHTTPProxy();
$bDidSomething = false;