Add first test for a generic ConfigurationSetter

We are blocked if a setter has to update several values.
ConfigurationSetter will be updated.

See https://github.com/FreshRSS/FreshRSS/issues/730
This commit is contained in:
Marien Fressinaud
2015-01-07 16:36:55 +01:00
parent 4c128e05a4
commit 2fd8a80878
2 changed files with 43 additions and 1 deletions

View File

@@ -17,10 +17,15 @@ class FreshRSS extends Minz_FrontController {
}
private function initConfiguration() {
$configuration_setter = new FreshRSS_ConfigurationSetter();
$current_user = Minz_Session::param('currentUser', '_');
Minz_Configuration::register('user',
join_path(USERS_PATH, $current_user, 'config.php'),
join_path(USERS_PATH, '_', 'config.default.php'));
join_path(USERS_PATH, '_', 'config.default.php'),
$configuration_setter);
$system_conf = Minz_Configuration::get('system');
$system_conf->_configurationSetter($configuration_setter);
}
private function initAuth() {

View File

@@ -0,0 +1,37 @@
<?php
class FreshRSS_ConfigurationSetter {
private $setters = array(
'language' => '_language',
'posts_per_page' => '_posts_per_page',
'view_mode' => '_view_mode',
);
public function handle($key, $value) {
if (isset($this->setters[$key])) {
$value = call_user_func(array($this, $this->setters[$key]), $value);
}
return $value;
}
private function _language($value) {
$languages = Minz_Translate::availableLanguages();
if (!isset($languages[$value])) {
$value = 'en';
}
return $value;
}
private function _posts_per_page($value) {
$value = intval($value);
return $value > 0 ? $value : 10;
}
private function _view_mode($value) {
if (!in_array($value, array('global', 'normal', 'reader'))) {
$value = 'normal';
}
return $value;
}
}