Skip to content

Commit

Permalink
Load INI path from outside of Toolkit directory
Browse files Browse the repository at this point in the history
Not sure is this should be it exactly, but per-site configuration and
system-wide (i.e managed by RPM) are common use cases; there may be
more. We should accomodate these when possible, because user
configuration in a source code directory is counter-intuitive and
inflexible.

Fixes #149
  • Loading branch information
NattyNarwhal committed May 31, 2021
1 parent 5328ad7 commit e7ce7dc
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion ToolkitApi/Toolkit.php
Original file line number Diff line number Diff line change
Expand Up @@ -2479,7 +2479,26 @@ static function getConfigValue($heading, $key, $default = null)
// if we haven't read config file yet, do so.
if (!isset(self::$_config)) {
// read/stat INI once and only once per request
self::$_config = parse_ini_file(CONFIG_FILE, true);
// We'll try these locations for the INI in order:
// - an environment variable (i.e so it can be set per-site)
// - a system dir (/QOpenSys prefixed on i)
// - where Toolkit is installed to (for back compat)
// It's clearer if we dynamically build it.
$locations = array(
CONFIG_FILE
);
array_unshift($locations, PHP_OS == "OS400" ?
"/QOpenSys/etc/php-toolkit.ini" : "etc/php-toolkit.ini");
$custom_ini_path = getenv("PHP_TOOLKIT_INI");
if ($custom_ini_path) {
array_unshift($locations, $custom_ini_path);
}
foreach ($locations as $location) {
self::$_config = parse_ini_file($location, true);
if (self::$_config !== false) {
break;
}
}
}

if (isset(self::$_config[$heading][$key])) {
Expand Down

0 comments on commit e7ce7dc

Please sign in to comment.