Skip to content

Commit e7ce7dc

Browse files
committed
Load INI path from outside of Toolkit directory
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
1 parent 5328ad7 commit e7ce7dc

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

ToolkitApi/Toolkit.php

+20-1
Original file line numberDiff line numberDiff line change
@@ -2479,7 +2479,26 @@ static function getConfigValue($heading, $key, $default = null)
24792479
// if we haven't read config file yet, do so.
24802480
if (!isset(self::$_config)) {
24812481
// read/stat INI once and only once per request
2482-
self::$_config = parse_ini_file(CONFIG_FILE, true);
2482+
// We'll try these locations for the INI in order:
2483+
// - an environment variable (i.e so it can be set per-site)
2484+
// - a system dir (/QOpenSys prefixed on i)
2485+
// - where Toolkit is installed to (for back compat)
2486+
// It's clearer if we dynamically build it.
2487+
$locations = array(
2488+
CONFIG_FILE
2489+
);
2490+
array_unshift($locations, PHP_OS == "OS400" ?
2491+
"/QOpenSys/etc/php-toolkit.ini" : "etc/php-toolkit.ini");
2492+
$custom_ini_path = getenv("PHP_TOOLKIT_INI");
2493+
if ($custom_ini_path) {
2494+
array_unshift($locations, $custom_ini_path);
2495+
}
2496+
foreach ($locations as $location) {
2497+
self::$_config = parse_ini_file($location, true);
2498+
if (self::$_config !== false) {
2499+
break;
2500+
}
2501+
}
24832502
}
24842503

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

0 commit comments

Comments
 (0)