App: fix setting default configuration values
This commit is contained in:
parent
6f47b2aea7
commit
4b73564f31
1 changed files with 15 additions and 3 deletions
18
src/App.php
18
src/App.php
|
@ -203,9 +203,19 @@ class App {
|
||||||
*
|
*
|
||||||
* @param string $key The configuration variable key
|
* @param string $key The configuration variable key
|
||||||
* @param mixed $value The configuration variable default value
|
* @param mixed $value The configuration variable default value
|
||||||
|
* @param boolean $override Set to true to override default value if already set (optional,
|
||||||
|
* default: false)
|
||||||
* @return boolean
|
* @return boolean
|
||||||
**/
|
**/
|
||||||
public static function set_default($key, $value) {
|
public static function set_default($key, $value, $override=false) {
|
||||||
|
if (is_array($value)) {
|
||||||
|
$result = true;
|
||||||
|
foreach($value as $subkey => $subvalue)
|
||||||
|
$result = $result && self :: set_default("$key.$subkey", $subvalue, $override);
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
if (self :: isset("default.$key") && !$override)
|
||||||
|
return true;
|
||||||
return Config::set("default.$key", $value, self :: $options);
|
return Config::set("default.$key", $value, self :: $options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -214,12 +224,14 @@ class App {
|
||||||
*
|
*
|
||||||
* @param array<string,mixed> $values Associative array of configuration variables name and
|
* @param array<string,mixed> $values Associative array of configuration variables name and
|
||||||
* default values
|
* default values
|
||||||
|
* @param boolean $override Set to true to override default value if already set (optional,
|
||||||
|
* default: false)
|
||||||
* @return boolean
|
* @return boolean
|
||||||
**/
|
**/
|
||||||
public static function set_defaults($values) {
|
public static function set_defaults($values, $override=false) {
|
||||||
$error = false;
|
$error = false;
|
||||||
foreach($values as $key => $value)
|
foreach($values as $key => $value)
|
||||||
if (!self :: set_default($key, $value))
|
if (!self :: set_default($key, $value, $override))
|
||||||
$error = true;
|
$error = true;
|
||||||
return !$error;
|
return !$error;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue