diff --git a/src/App.php b/src/App.php index 3fe0fa8..fd23105 100644 --- a/src/App.php +++ b/src/App.php @@ -203,9 +203,19 @@ class App { * * @param string $key The configuration variable key * @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 **/ - 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); } @@ -214,12 +224,14 @@ class App { * * @param array $values Associative array of configuration variables name and * default values + * @param boolean $override Set to true to override default value if already set (optional, + * default: false) * @return boolean **/ - public static function set_defaults($values) { + public static function set_defaults($values, $override=false) { $error = false; foreach($values as $key => $value) - if (!self :: set_default($key, $value)) + if (!self :: set_default($key, $value, $override)) $error = true; return !$error; }