Compare commits

...

4 commits

Author SHA1 Message Date
Benjamin Renard
4f46c38643
Add possibility to define config parameters default value in app's options 2023-02-27 17:52:51 +01:00
Benjamin Renard
7e8b6ee5f2
App::isset(): remove unused parameter $config 2023-02-27 17:44:19 +01:00
Benjamin Renard
eea359056b
Tpl: defaulty define upload_max_filesize variable from config 2023-02-27 16:58:28 +01:00
Benjamin Renard
765844bee9
Move handling webstats_js_code parameter in core code 2023-02-27 16:35:35 +01:00
7 changed files with 51 additions and 9 deletions

View file

@ -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
@ -302,6 +302,6 @@ email:
catch_all: false
# Web Stats JS code
webstats_js_code: ''
#webstats_js_code: ''
# vim: tabstop=2 shiftwidth=2 softtabstop=2 expandtab

View file

@ -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
);

View file

@ -30,9 +30,6 @@ function define_common_template_variables($event) {
$status_list:array()
);
Tpl :: assign('admin', isset($admin) && $admin);
Tpl :: assign(
'webstats_js_code',
App::get('webstats_js_code', null, 'string'));
}
Hook :: register('before_displaying_template', 'define_common_template_variables');

View file

@ -302,6 +302,6 @@ email:
catch_all: false
# Web Stats JS code
webstats_js_code: ''
#webstats_js_code: ''
# vim: tabstop=2 shiftwidth=2 softtabstop=2 expandtab

View file

@ -38,6 +38,9 @@ App::init(
"$root_dir_path/static"
),
),
'default' => array(
// Set here your configuration parameters default value
),
),
$root_dir_path
);

View file

@ -95,10 +95,9 @@ class App {
* Check if a specific configuration variable is set
*
* @param string $key The configuration variable key
* @param array|null $config Optional configuration to use instead of current loaded configuration
* @return bool
**/
public static function isset($key, &$config=null) {
public static function isset($key) {
return Config::isset($key, self :: $options) || (Config::loaded() && Config::isset($key));
}
@ -116,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,
@ -125,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
*

View file

@ -380,6 +380,17 @@ class Tpl {
// Authenticated user info
if (Auth::user())
self :: assign('auth_user', Auth::user());
// Webstats JS code
Tpl :: assign(
'webstats_js_code',
App::get('webstats_js_code', null, 'string'));
// Upload max size
if (App::get('upload_max_filesize', null, 'int'))
Tpl :: assign(
'upload_max_filesize',
App::get('upload_max_filesize', null, 'int'));
}
/**