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); $rc = include ($this->confFile);
if ($rc !== 1) if ($rc !== 1)
throw new Exception ("Error in configuration file", 500); 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",
if (! is_array ($conf[$param])) $param), 500);
return $conf[$param]; // Create a conf where all the keys are defined. If the keys are already
// if the configuration is an array, check if all the keys are defined // define, use them, or use the default ones
// or use the default // Don't allow keys not defined in default ones
foreach ($this->default[$param] as $key=>$val) foreach ($this->default[$param] as $key=>$val)
{ {
if ($key === "not configured")
{
if (! array_key_exists ($param, $conf))
continue;
foreach ($conf[$param] as $k=>$v)
{
$conf[$param][$k] = array_replace_recursive ($val,
$conf[$param][$k]);
}
continue;
}
if (! isset ($conf[$param][$key])) if (! isset ($conf[$param][$key]))
$conf[$param][$key] = $val; $conf[$param][$key] = $val;
elseif (is_array ($val))
$conf[$param][$key] = array_replace_recursive ($val,
$conf[$param][$key]);
} }
foreach ($conf[$param] as $key=>$val) if (! array_key_exists ($param, $conf))
{
if ($key === "not configured")
continue;
if (is_array ($val))
{
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;
}
}
}
if (count ($conf[$param]) > 1 && isset ($conf[$param]["not configured"]))
unset ($conf[$param]["not configured"]);
return $conf[$param];
}
return $this->default[$param]; return $this->default[$param];
return $conf[$param];
} }
/** Define a value for the parameter in the config file. Add all the default /** Define a value for the parameter in the config file. Add all the default