config : allow the defaults vals to be returned in array of arrays

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@2945 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2016-07-25 11:28:53 +00:00
parent 71975da3cb
commit c3ad1085c1

View File

@@ -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