Add possibility to define config parameters default value in app's options
This commit is contained in:
parent
7e8b6ee5f2
commit
4f46c38643
4 changed files with 37 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
);
|
||||
|
|
|
@ -38,6 +38,9 @@ App::init(
|
|||
"$root_dir_path/static"
|
||||
),
|
||||
),
|
||||
'default' => array(
|
||||
// Set here your configuration parameters default value
|
||||
),
|
||||
),
|
||||
$root_dir_path
|
||||
);
|
||||
|
|
26
src/App.php
26
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
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue