aurweb/web/lib/confparser.inc.php
Lukas Fleischer 1613bd2f29 confparser.inc.php: Support alternative config path
Add a AUR_CONFIG environment variable that can be used to specify an
alternative configuration file, similar to the feature introduced in
ecbf32f (git-interface: Add AUR_CONFIG environment variable,
2016-08-03).

Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2017-02-08 19:18:27 +01:00

43 lines
822 B
PHP

<?php
function config_load() {
global $AUR_CONFIG;
if (!isset($AUR_CONFIG)) {
$path = getenv('AUR_CONFIG');
if (!$path) {
$path = "/etc/aurweb/config";
}
$AUR_CONFIG = parse_ini_file($path, true, INI_SCANNER_RAW);
}
}
function config_get($section, $key) {
global $AUR_CONFIG;
config_load();
return $AUR_CONFIG[$section][$key];
}
function config_get_int($section, $key) {
return intval(config_get($section, $key));
}
function config_get_bool($section, $key) {
$val = strtolower(config_get($section, $key));
return ($val == 'yes' || $val == 'true' || $val == '1');
}
function config_items($section) {
global $AUR_CONFIG;
config_load();
return $AUR_CONFIG[$section];
}
function config_section_exists($key) {
global $AUR_CONFIG;
config_load();
return array_key_exists($key, $AUR_CONFIG);
}