aboutsummaryrefslogtreecommitdiff
path: root/app/Models/ConfigurationSetter.php
diff options
context:
space:
mode:
authorGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2015-01-07 16:36:55 +0100
committerGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2015-01-07 16:36:55 +0100
commit2fd8a80878441cf59b1689b1765633694cb320b6 (patch)
tree32e329c64d66337bf7539bf502d062749c90aef7 /app/Models/ConfigurationSetter.php
parent4c128e05a4b1245525fd3eae7733e022ee805acd (diff)
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
Diffstat (limited to 'app/Models/ConfigurationSetter.php')
-rw-r--r--app/Models/ConfigurationSetter.php37
1 files changed, 37 insertions, 0 deletions
diff --git a/app/Models/ConfigurationSetter.php b/app/Models/ConfigurationSetter.php
new file mode 100644
index 000000000..e30cb0187
--- /dev/null
+++ b/app/Models/ConfigurationSetter.php
@@ -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;
+ }
+}