From e7ce7dcce345ed5026d0668510cf51a3ba876443 Mon Sep 17 00:00:00 2001 From: Calvin Buckley Date: Mon, 31 May 2021 12:18:55 -0300 Subject: [PATCH] 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 --- ToolkitApi/Toolkit.php | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/ToolkitApi/Toolkit.php b/ToolkitApi/Toolkit.php index 3d02f03..754a103 100644 --- a/ToolkitApi/Toolkit.php +++ b/ToolkitApi/Toolkit.php @@ -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])) {