diff --git a/config.php b/config.php index b611108..52036c4 100644 --- a/config.php +++ b/config.php @@ -88,37 +88,34 @@ class config $rc = include ($this->confFile); if ($rc !== 1) throw new Exception ("Error in configuration file", 500); - if (array_key_exists ($param, $conf)) + if (! array_key_exists ($param, $this->default)) + throw new Exception (sprintf ("Configuration parameter '%s' not defined", + $param), 500); + // Create a conf where all the keys are defined. If the keys are already + // define, use them, or use the default ones + // Don't allow keys not defined in default ones + foreach ($this->default[$param] as $key=>$val) { - if (! is_array ($conf[$param])) - return $conf[$param]; - // if the configuration is an array, check if all the keys are defined - // or use the default - foreach ($this->default[$param] as $key=>$val) + if ($key === "not configured") { - if (! isset ($conf[$param][$key])) - $conf[$param][$key] = $val; - } - foreach ($conf[$param] as $key=>$val) - { - if ($key === "not configured") + if (! array_key_exists ($param, $conf)) continue; - if (is_array ($val)) + foreach ($conf[$param] as $k=>$v) { - if (! isset ($this->default[$param]["not configured"])) - continue; - foreach ($this->default[$param]["not configured"] as $k=>$v) - { - if (! array_key_exists ($k, $conf[$param][$key])) - $conf[$param][$key][$k] = $v; - } + $conf[$param][$k] = array_replace_recursive ($val, + $conf[$param][$k]); } + continue; } - if (count ($conf[$param]) > 1 && isset ($conf[$param]["not configured"])) - unset ($conf[$param]["not configured"]); - return $conf[$param]; + if (! isset ($conf[$param][$key])) + $conf[$param][$key] = $val; + elseif (is_array ($val)) + $conf[$param][$key] = array_replace_recursive ($val, + $conf[$param][$key]); } - return $this->default[$param]; + if (! array_key_exists ($param, $conf)) + return $this->default[$param]; + return $conf[$param]; } /** Define a value for the parameter in the config file. Add all the default