1 | <?php |
||
20 | class EloquentSetting implements SettingInterface |
||
21 | { |
||
22 | /** |
||
23 | * @var SystemSetting |
||
24 | */ |
||
25 | private $model; |
||
26 | |||
27 | /** |
||
28 | * EloquentSetting constructor. |
||
29 | * @param SystemSetting $model |
||
30 | */ |
||
31 | 6 | public function __construct(SystemSetting $model) |
|
35 | |||
36 | /** |
||
37 | * @param array $settings |
||
38 | * @return bool |
||
39 | */ |
||
40 | 6 | public function setSetting(array $settings) |
|
41 | { |
||
42 | 6 | if (!is_array($settings)) { |
|
43 | return false; |
||
44 | } |
||
45 | |||
46 | 6 | foreach ($settings as $key => $val) { |
|
47 | 6 | $var = $this->model->where('key', $key)->first(); |
|
|
|||
48 | 6 | if ($var) { |
|
49 | $var->value = $val; |
||
50 | $var->save(); |
||
51 | } else { |
||
52 | 6 | $var = $this->model->create(['key' => $key, 'value' => $val]); |
|
53 | } |
||
54 | } |
||
55 | |||
56 | 6 | return $var; |
|
57 | } |
||
58 | |||
59 | /** |
||
60 | * @param $key |
||
61 | * @return string |
||
62 | */ |
||
63 | 1 | public function getSetting($key) |
|
72 | |||
73 | /** |
||
74 | * @return array |
||
75 | */ |
||
76 | 2 | public function allToArray() |
|
85 | } |
||
86 |
If you implement
__call
and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__call
is implemented by a parent class and only the child class knows which methods exist: