Merge branch 'conf-path-handling'

This commit is contained in:
El RIDO 2021-08-19 19:33:19 +02:00
commit 82f1431440
No known key found for this signature in database
GPG Key ID: 0F5C940A6BD81F92
2 changed files with 16 additions and 9 deletions

View File

@ -161,7 +161,7 @@ class = Filesystem
[model_options] [model_options]
dir = PATH "data" dir = PATH "data"
[model] ;[model]
; example of a Google Cloud Storage configuration ; example of a Google Cloud Storage configuration
;class = GoogleCloudStorage ;class = GoogleCloudStorage
;[model_options] ;[model_options]

View File

@ -101,16 +101,23 @@ class Configuration
*/ */
public function __construct() public function __construct()
{ {
$basePaths = array();
$config = array(); $config = array();
$basePath = (getenv('CONFIG_PATH') !== false ? getenv('CONFIG_PATH') : PATH . 'cfg') . DIRECTORY_SEPARATOR; $configPath = getenv('CONFIG_PATH');
$configFile = $basePath . 'conf.php'; if ($configPath !== false && !empty($configPath)) {
$basePaths[] = $configPath;
if (is_readable($configFile)) { }
$config = parse_ini_file($configFile, true); $basePaths[] = PATH . 'cfg';
foreach (array('main', 'model', 'model_options') as $section) { foreach ($basePaths as $basePath) {
if (!array_key_exists($section, $config)) { $configFile = $basePath . DIRECTORY_SEPARATOR . 'conf.php';
throw new Exception(I18n::_('PrivateBin requires configuration section [%s] to be present in configuration file.', $section), 2); if (is_readable($configFile)) {
$config = parse_ini_file($configFile, true);
foreach (array('main', 'model', 'model_options') as $section) {
if (!array_key_exists($section, $config)) {
throw new Exception(I18n::_('PrivateBin requires configuration section [%s] to be present in configuration file.', $section), 2);
}
} }
break;
} }
} }