ConfigurationSetter.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. class FreshRSS_ConfigurationSetter {
  3. /**
  4. * Return if the given key is supported by this setter.
  5. * @param $key the key to test.
  6. * @return true if the key is supported, false else.
  7. */
  8. public function support($key) {
  9. $name_setter = '_' . $key;
  10. return is_callable(array($this, $name_setter));
  11. }
  12. /**
  13. * Set the given key in data with the current value.
  14. * @param $data an array containing the list of all configuration data.
  15. * @param $key the key to update.
  16. * @param $value the value to set.
  17. */
  18. public function handle(&$data, $key, $value) {
  19. $name_setter = '_' . $key;
  20. call_user_func_array(array($this, $name_setter), array(&$data, $value));
  21. }
  22. /**
  23. * The (long) list of setters.
  24. */
  25. private function _language(&$data, $value) {
  26. $languages = Minz_Translate::availableLanguages();
  27. if (!isset($languages[$value])) {
  28. $value = 'en';
  29. }
  30. $data['language'] = $value;
  31. }
  32. private function _posts_per_page(&$data, $value) {
  33. $value = intval($value);
  34. $data['posts_per_page'] = $value > 0 ? $value : 10;
  35. }
  36. private function _view_mode(&$data, $value) {
  37. if (!in_array($value, array('global', 'normal', 'reader'))) {
  38. $value = 'normal';
  39. }
  40. $data['view_mode'] = $value;
  41. }
  42. }