]>
Commit | Line | Data |
---|---|---|
1 | <?php | |
2 | ||
3 | namespace Shaarli; | |
4 | ||
5 | use Shaarli\Config\ConfigManager; | |
6 | ||
7 | /** | |
8 | * Fake ConfigManager | |
9 | */ | |
10 | class FakeConfigManager extends ConfigManager | |
11 | { | |
12 | protected $values = []; | |
13 | ||
14 | /** | |
15 | * Initialize with test values | |
16 | * | |
17 | * @param array $values Initial values | |
18 | */ | |
19 | public function __construct($values = []) | |
20 | { | |
21 | $this->values = $values; | |
22 | } | |
23 | ||
24 | /** | |
25 | * Set a given value | |
26 | * | |
27 | * @param string $key Key of the value to set | |
28 | * @param mixed $value Value to set | |
29 | */ | |
30 | public function set($key, $value, $write = false, $isLoggedIn = false) | |
31 | { | |
32 | $this->values[$key] = $value; | |
33 | } | |
34 | ||
35 | /** | |
36 | * Get a given configuration value | |
37 | * | |
38 | * @param string $key Index of the value to retrieve | |
39 | * | |
40 | * @return mixed The value if set, else the name of the key | |
41 | */ | |
42 | public function get($key, $default = '') | |
43 | { | |
44 | if (isset($this->values[$key])) { | |
45 | return $this->values[$key]; | |
46 | } | |
47 | return $key; | |
48 | } | |
49 | ||
50 | /** | |
51 | * Check if a setting exists | |
52 | * | |
53 | * @param string $setting Asked setting, keys separated with dots | |
54 | * | |
55 | * @return bool true if the setting exists, false otherwise | |
56 | */ | |
57 | public function exists($setting) | |
58 | { | |
59 | return array_key_exists($setting, $this->values); | |
60 | } | |
61 | } |