| 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 | 5 | public function setSetting(array $settings) |
|
| 41 | { |
||
| 42 | 5 | if (count($settings)<=0) { |
|
| 43 | 1 | return false; |
|
| 44 | } |
||
| 45 | |||
| 46 | 5 | foreach ($settings as $key => $val) { |
|
| 47 | 5 | $var = $this->model->where('key', $key)->first(); |
|
|
|
|||
| 48 | 5 | if ($var) { |
|
| 49 | $var->value = $val; |
||
| 50 | $var->save(); |
||
| 51 | } else { |
||
| 52 | 5 | $var = $this->model->create(['key' => $key, 'value' => $val]); |
|
| 53 | } |
||
| 54 | } |
||
| 55 | |||
| 56 | 5 | return $var; |
|
| 57 | } |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @param $key |
||
| 61 | * @param null $input |
||
| 62 | * @return bool|mixed|string |
||
| 63 | */ |
||
| 64 | 1 | public function getSetting($key,$input=null) |
|
| 79 | |||
| 80 | /** |
||
| 81 | * @return array |
||
| 82 | */ |
||
| 83 | 2 | public function allToArray() |
|
| 92 | } |
||
| 93 |
If you implement
__calland 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
__callis implemented by a parent class and only the child class knows which methods exist: