aboutsummaryrefslogtreecommitdiff
path: root/app/Models/ConfigurationSetter.php
blob: 801e1162580ff697e30aed1c7270c28d8f604828 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php

class FreshRSS_ConfigurationSetter {
	/**
	 * 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));
	}

	/**
	 * 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));
	}

	/**
	 * The (long) list of setters.
	 */
	private function _language(&$data, $value) {
		$languages = Minz_Translate::availableLanguages();
		if (!isset($languages[$value])) {
			$value = 'en';
		}
		$data['language'] = $value;
	}

	private function _posts_per_page(&$data, $value) {
		$value = intval($value);
		$data['posts_per_page'] = $value > 0 ? $value : 10;
	}

	private function _view_mode(&$data, $value) {
		if (!in_array($value, array('global', 'normal', 'reader'))) {
			$value = 'normal';
		}
		$data['view_mode'] =  $value;
	}
}