1 | <?php |
||||
2 | |||||
3 | namespace Glorand\Model\Settings\Managers; |
||||
4 | |||||
5 | use Glorand\Model\Settings\Contracts\SettingsManagerContract; |
||||
6 | use Glorand\Model\Settings\Exceptions\ModelSettingsException; |
||||
7 | use Glorand\Model\Settings\Traits\HasSettings; |
||||
8 | use Illuminate\Database\Eloquent\Model; |
||||
9 | |||||
10 | /** |
||||
11 | * Class AbstractSettingsManager |
||||
12 | * @package Glorand\Model\Settings\Managers |
||||
13 | */ |
||||
14 | abstract class AbstractSettingsManager implements SettingsManagerContract |
||||
15 | { |
||||
16 | /** @var \Illuminate\Database\Eloquent\Model */ |
||||
17 | protected $model; |
||||
18 | |||||
19 | /** |
||||
20 | * AbstractSettingsManager constructor. |
||||
21 | * @param \Illuminate\Database\Eloquent\Model $model |
||||
22 | * @throws \Glorand\Model\Settings\Exceptions\ModelSettingsException |
||||
23 | */ |
||||
24 | 18 | public function __construct(Model $model) |
|||
25 | { |
||||
26 | 18 | $this->model = $model; |
|||
27 | 18 | if (!in_array(HasSettings::class, class_uses_recursive($this->model))) { |
|||
28 | 1 | throw new ModelSettingsException('Wrong model, missing HasSettings trait.'); |
|||
29 | } |
||||
30 | 17 | } |
|||
31 | |||||
32 | /** |
||||
33 | * @return array |
||||
34 | */ |
||||
35 | 17 | public function all(): array |
|||
36 | { |
||||
37 | 17 | return $this->model->getSettingsValue(); |
|||
38 | } |
||||
39 | |||||
40 | /** |
||||
41 | * @param string $path |
||||
42 | * @return bool |
||||
43 | */ |
||||
44 | 2 | public function has(string $path): bool |
|||
45 | { |
||||
46 | 2 | return array_has($this->all(), $path); |
|||
0 ignored issues
–
show
|
|||||
47 | } |
||||
48 | |||||
49 | /** |
||||
50 | * @param string|null $path |
||||
51 | * @param null $default |
||||
52 | * @return array|mixed |
||||
53 | */ |
||||
54 | 4 | public function get(string $path = null, $default = null) |
|||
55 | { |
||||
56 | 4 | return $path ? array_get($this->all(), $path, $default) : $this->all(); |
|||
0 ignored issues
–
show
The function
array_get() has been deprecated: Arr::get() should be used directly instead. Will be removed in Laravel 5.9.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This function has been deprecated. The supplier of the function has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.
Loading history...
|
|||||
57 | } |
||||
58 | |||||
59 | /** |
||||
60 | * @param string $path |
||||
61 | * @param mixed $value |
||||
62 | * @return \Glorand\Model\Settings\Contracts\SettingsManagerContract |
||||
63 | */ |
||||
64 | 2 | public function update(string $path, $value): SettingsManagerContract |
|||
65 | { |
||||
66 | 2 | return $this->set($path, $value); |
|||
67 | } |
||||
68 | } |
||||
69 |
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.