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
pull/749/head
Marien Fressinaud 10 years ago
parent 4c128e05a4
commit 2fd8a80878
  1. 7
      app/FreshRSS.php
  2. 37
      app/Models/ConfigurationSetter.php

@ -17,10 +17,15 @@ class FreshRSS extends Minz_FrontController {
} }
private function initConfiguration() { private function initConfiguration() {
$configuration_setter = new FreshRSS_ConfigurationSetter();
$current_user = Minz_Session::param('currentUser', '_'); $current_user = Minz_Session::param('currentUser', '_');
Minz_Configuration::register('user', Minz_Configuration::register('user',
join_path(USERS_PATH, $current_user, 'config.php'), 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() { private function initAuth() {

@ -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;
}
}
Loading…
Cancel
Save