1 | <?php |
||
11 | class InMemorySettingRepository implements SettingRepositoryInterface |
||
12 | { |
||
13 | private $values = []; |
||
14 | |||
15 | |||
16 | 7 | public function __construct($settingPlainRows) |
|
17 | { |
||
18 | 7 | foreach ($settingPlainRows as $key) { |
|
19 | 7 | $name = $key[0]; |
|
20 | 7 | $value = $key[1]; |
|
21 | 7 | $section = $key[2]; |
|
22 | 7 | $this->set($name, $value, $section); |
|
23 | } |
||
24 | 7 | } |
|
25 | |||
26 | /** |
||
27 | * {@inheritdoc} |
||
28 | */ |
||
29 | 6 | public function findWithinSection(Key $settingKey, Section $section) |
|
30 | { |
||
31 | 6 | $key = $settingKey->key(); |
|
32 | 6 | $sectionName = $section->name(); |
|
33 | |||
34 | 6 | if (!isset($this->values[$key][$sectionName])) { |
|
35 | 3 | return null; |
|
36 | } |
||
37 | |||
38 | 4 | return Setting::issue( |
|
39 | $settingKey, |
||
40 | 4 | $this->values[$key][$sectionName], |
|
41 | 4 | new Section($sectionName) |
|
42 | ); |
||
43 | } |
||
44 | |||
45 | /** |
||
46 | * {@inheritdoc} |
||
47 | */ |
||
48 | 2 | public function save(Setting $setting) |
|
52 | |||
53 | /** |
||
54 | * @param $name |
||
55 | * @param $value |
||
56 | * @param $section |
||
57 | */ |
||
58 | 7 | private function set($name, $value, $section) |
|
64 | } |
||
65 |