1 | <?php |
||
2 | |||
3 | namespace Chuckbe\Chuckcms\Models; |
||
4 | |||
5 | use Eloquent; |
||
6 | |||
7 | class Module extends Eloquent |
||
8 | { |
||
9 | /** |
||
10 | * The attributes that are mass assignable. |
||
11 | * |
||
12 | * @var array |
||
13 | */ |
||
14 | protected $fillable = [ |
||
15 | 'name', 'slug', 'hintpath', 'path', 'type', 'version', 'author', 'json', |
||
16 | ]; |
||
17 | |||
18 | /** |
||
19 | * The attributes that are castable. |
||
20 | * |
||
21 | * @var array |
||
22 | */ |
||
23 | protected $casts = [ |
||
24 | 'json' => 'array', |
||
25 | ]; |
||
26 | |||
27 | public function getSettingsAttribute() |
||
28 | { |
||
29 | if (array_key_exists('settings', $this->json)) { |
||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||
30 | return $this->json['settings']; |
||
31 | } |
||
32 | |||
33 | if (!array_key_exists('admin', $this->json)) { |
||
34 | return []; |
||
35 | } |
||
36 | |||
37 | if (!array_key_exists('settings', $this->json['admin'])) { |
||
38 | return []; |
||
39 | } |
||
40 | |||
41 | return $this->json['admin']['settings']; |
||
42 | } |
||
43 | |||
44 | public function getSetting(string $string) |
||
45 | { |
||
46 | $setting = $this->resolveSetting($string); |
||
47 | |||
48 | return !is_null($setting) ? $setting : null; |
||
49 | } |
||
50 | |||
51 | private function resolveSetting($var) |
||
52 | { |
||
53 | $setting = $this->settings; |
||
0 ignored issues
–
show
The property
settings does not exist on Chuckbe\Chuckcms\Models\Module . Since you implemented __get , consider adding a @property annotation.
![]() |
|||
54 | $split = explode('.', $var); |
||
55 | foreach ($split as $value) { |
||
56 | if (array_key_exists($value, $setting)) { |
||
57 | $setting = $setting[$value]; |
||
58 | } else { |
||
59 | return null; |
||
60 | } |
||
61 | } |
||
62 | |||
63 | return $setting; |
||
64 | } |
||
65 | } |
||
66 |