A free, self-hostable news aggregator…
Change way to call configuration setter.
Marien Fressinaudfb614ab80cf0
diff --git a/app/Models/ConfigurationSetter.php b/app/Models/ConfigurationSetter.phpindex e30cb0187..801e11625 100644--- a/app/Models/ConfigurationSetter.php+++ b/app/Models/ConfigurationSetter.php@@ -1,37 +1,47 @@<?phpclass 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;}}diff --git a/lib/Minz/Configuration.php b/lib/Minz/Configuration.phpindex 019b47fae..6044fc269 100644--- a/lib/Minz/Configuration.php+++ b/lib/Minz/Configuration.php@@ -176,11 +176,9 @@ class Minz_Configuration {* @param $value the value to set. If null, the key is removed from the configuration.*/public function _param($key, $value = null) {- if (!is_null($this->configuration_setter)) {- $value = $this->configuration_setter->handle($key, $value);- }-- if (isset($this->data[$key]) && is_null($value)) {+ if (!is_null($this->configuration_setter) && $this->configuration_setter->support($key)) {+ $this->configuration_setter->handle($this->data, $key, $value);+ } elseif (isset($this->data[$key]) && is_null($value)) {unset($this->data[$key]);} elseif (!is_null($value)) {$this->data[$key] = $value;