1 | <?php |
||
10 | class SectionQuery implements SettingBagInterface |
||
11 | { |
||
12 | /** |
||
13 | * @var SettingRepositoryInterface |
||
14 | */ |
||
15 | private $settingRepository; |
||
16 | |||
17 | /** |
||
18 | * @var Section |
||
19 | */ |
||
20 | private $section; |
||
21 | |||
22 | 6 | public function __construct(SettingRepositoryInterface $settingRepository, Section $section) |
|
27 | |||
28 | 6 | public function get($key, $default = null) |
|
34 | |||
35 | 2 | public function set($key, $value) |
|
36 | { |
||
37 | 2 | $aKey = Key::fromString($key); |
|
38 | 2 | $aValue = Value::fromString($value); |
|
39 | |||
40 | 2 | $setting = $this->find($aKey); |
|
41 | |||
42 | 2 | if (null === $setting) { |
|
43 | 1 | $setting = Setting::issue($aKey, $aValue, $this->section); |
|
44 | } |
||
45 | |||
46 | 2 | $setting->changeValue($aValue); |
|
47 | |||
48 | 2 | $this->settingRepository->save($setting); |
|
49 | 2 | } |
|
50 | |||
51 | /** |
||
52 | * @param Key $key |
||
53 | * @return Setting|null |
||
54 | */ |
||
55 | 6 | private function find(Key $key) |
|
59 | } |
||
60 |