diff --git a/example/includes/config.yml b/example/includes/config.yml index 4a73402..7013bd3 100644 --- a/example/includes/config.yml +++ b/example/includes/config.yml @@ -95,8 +95,8 @@ templates: # Translations # i18n: - # Default locale (see locales directory for available languages list) - default_locale: 'en_US.UTF8' + # Default locale (see locales directory for available languages list, default: 'en_US.UTF8') + #default_locale: 'en_US.UTF8' # # Session diff --git a/example/includes/core.php b/example/includes/core.php index 30605b3..0bdad7e 100644 --- a/example/includes/core.php +++ b/example/includes/core.php @@ -38,6 +38,12 @@ App::init( "$root_dir_path/static" ), ), + 'default' => array( + 'upload_max_filesize' => 10485760, + 'i18n' => array( + 'default_locale' => "en_US.UTF8", + ), + ), ), $root_dir_path ); diff --git a/skel/includes/core.php b/skel/includes/core.php index ac6661d..f3f9420 100644 --- a/skel/includes/core.php +++ b/skel/includes/core.php @@ -38,6 +38,9 @@ App::init( "$root_dir_path/static" ), ), + 'default' => array( + // Set here your configuration parameters default value + ), ), $root_dir_path ); diff --git a/src/App.php b/src/App.php index 7fa6480..c043f86 100644 --- a/src/App.php +++ b/src/App.php @@ -115,6 +115,7 @@ class App { * @return mixed The configuration variable value **/ public static function get($key, $default=null, $cast=null, $split=true) { + $default = self :: get_default($key, $default, $cast, $split); return Config::get( $key, Config::loaded()?Config::get($key, $default, $cast, $split):$default, @@ -124,6 +125,31 @@ class App { ); } + /** + * Get a specific option default value + * + * @param string $key The configuration variable key + * @param mixed $default Default value provided by context + * (optional, priority if not nul, default : null) + * @param string $cast The type of expected value. The configuration variable + * default value will be cast as this type. Could be : bool, int, + * float or string. (Optional, default : raw value) + * @param bool $split If true, $cast is 'array' and value retreived from configuration + * is a string, split the value by comma (optional, default: true) + * @return mixed The configuration variable default value + **/ + public static function get_default($key, $default=null, $cast=null, $split=true) { + if (!is_null($default)) + return $default; + return Config::get( + "default.$key", + $default, + $cast, + $split, + self :: $options + ); + } + /** * Set a specific option value *