diff options
| author | 2015-01-07 17:36:29 +0100 | |
|---|---|---|
| committer | 2015-01-07 17:36:29 +0100 | |
| commit | fb614ab80cf038416e5451b4f6f25f421d75d8e4 (patch) | |
| tree | 94ac657f352caaa6f9086e0382b7f39a133dbe8e /app/Models/ConfigurationSetter.php | |
| parent | 2fd8a80878441cf59b1689b1765633694cb320b6 (diff) | |
Change way to call configuration setter.
- Add a support($key) method which return if the given key is supported by
the setter.
- Change handle signature by adding a $data param which must be passed by
reference.
See https://github.com/FreshRSS/FreshRSS/issues/730
Diffstat (limited to 'app/Models/ConfigurationSetter.php')
| -rw-r--r-- | app/Models/ConfigurationSetter.php | 44 |
1 files changed, 27 insertions, 17 deletions
diff --git a/app/Models/ConfigurationSetter.php b/app/Models/ConfigurationSetter.php index e30cb0187..801e11625 100644 --- a/app/Models/ConfigurationSetter.php +++ b/app/Models/ConfigurationSetter.php @@ -1,37 +1,47 @@ <?php class FreshRSS_ConfigurationSetter { - private $setters = array( - 'language' => '_language', - 'posts_per_page' => '_posts_per_page', - 'view_mode' => '_view_mode', - ); + /** + * Return if the given key is supported by this setter. + * @param $key the key to test. + * @return true if the key is supported, false else. + */ + public function support($key) { + $name_setter = '_' . $key; + return is_callable(array($this, $name_setter)); + } - public function handle($key, $value) { - if (isset($this->setters[$key])) { - $value = call_user_func(array($this, $this->setters[$key]), $value); - } - return $value; + /** + * Set the given key in data with the current value. + * @param $data an array containing the list of all configuration data. + * @param $key the key to update. + * @param $value the value to set. + */ + public function handle(&$data, $key, $value) { + $name_setter = '_' . $key; + call_user_func_array(array($this, $name_setter), array(&$data, $value)); } - private function _language($value) { + /** + * The (long) list of setters. + */ + private function _language(&$data, $value) { $languages = Minz_Translate::availableLanguages(); if (!isset($languages[$value])) { $value = 'en'; } - - return $value; + $data['language'] = $value; } - private function _posts_per_page($value) { + private function _posts_per_page(&$data, $value) { $value = intval($value); - return $value > 0 ? $value : 10; + $data['posts_per_page'] = $value > 0 ? $value : 10; } - private function _view_mode($value) { + private function _view_mode(&$data, $value) { if (!in_array($value, array('global', 'normal', 'reader'))) { $value = 'normal'; } - return $value; + $data['view_mode'] = $value; } } |
