1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Fenos\Notifynder\Collections; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Arr; |
6
|
|
|
use InvalidArgumentException; |
7
|
|
|
use Fenos\Notifynder\Contracts\ConfigContract; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class Config. |
11
|
|
|
*/ |
12
|
|
|
class Config implements ConfigContract |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var array |
16
|
|
|
*/ |
17
|
|
|
protected $items; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Config constructor. |
21
|
|
|
*/ |
22
|
|
|
public function __construct() |
23
|
|
|
{ |
24
|
|
|
$this->reload(); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @return bool |
29
|
|
|
*/ |
30
|
|
|
public function isPolymorphic() |
31
|
|
|
{ |
32
|
|
|
return (bool) $this->get('polymorphic'); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @return bool |
37
|
|
|
*/ |
38
|
|
|
public function isStrict() |
39
|
|
|
{ |
40
|
|
|
return (bool) $this->get('strict_extra'); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @return bool |
45
|
|
|
*/ |
46
|
|
|
public function isTranslated() |
47
|
|
|
{ |
48
|
|
|
return (bool) $this->get('translation.enabled'); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @return string |
53
|
|
|
* @throws InvalidArgumentException |
54
|
|
|
*/ |
55
|
|
|
public function getNotifiedModel() |
56
|
|
|
{ |
57
|
|
|
$class = $this->get('model'); |
58
|
|
|
if (class_exists($class)) { |
59
|
|
|
return $class; |
60
|
|
|
} |
61
|
|
|
throw new InvalidArgumentException("The model class [{$class}] doesn't exist."); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @return array |
66
|
|
|
*/ |
67
|
|
|
public function getAdditionalFields() |
68
|
|
|
{ |
69
|
|
|
return Arr::flatten($this->get('additional_fields', [])); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return array |
74
|
|
|
*/ |
75
|
|
|
public function getAdditionalRequiredFields() |
76
|
|
|
{ |
77
|
|
|
return Arr::flatten($this->get('additional_fields.required', [])); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @return string |
82
|
|
|
*/ |
83
|
|
|
public function getTranslationDomain() |
84
|
|
|
{ |
85
|
|
|
return $this->get('translation.domain', 'notifynder'); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @param string $key |
90
|
|
|
* @param null|mixed $default |
91
|
|
|
* @return mixed |
92
|
|
|
*/ |
93
|
|
|
public function get($key, $default = null) |
94
|
|
|
{ |
95
|
|
|
return Arr::get($this->items, $key, $default); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @param string $key |
100
|
|
|
* @return bool |
101
|
|
|
*/ |
102
|
|
|
public function has($key) |
103
|
|
|
{ |
104
|
|
|
return Arr::has($this->items, $key); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @param string $key |
109
|
|
|
* @param null $value |
110
|
|
|
*/ |
111
|
|
|
public function set($key, $value = null) |
112
|
|
|
{ |
113
|
|
|
Arr::set($this->items, $key, $value); |
114
|
|
|
app('config')->set('notifynder.'.$key, $value); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @param string $key |
119
|
|
|
*/ |
120
|
|
|
public function forget($key) |
121
|
|
|
{ |
122
|
|
|
Arr::forget($this->items, $key); |
123
|
|
|
app('config')->offsetUnset('notifynder.'.$key); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
public function reload() |
127
|
|
|
{ |
128
|
|
|
$this->items = app('config')->get('notifynder'); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @param string $key |
133
|
|
|
* @return mixed |
134
|
|
|
*/ |
135
|
|
|
public function __get($key) |
136
|
|
|
{ |
137
|
|
|
return $this->get($key); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @param string $key |
142
|
|
|
* @param mixed $value |
143
|
|
|
*/ |
144
|
|
|
public function __set($key, $value) |
145
|
|
|
{ |
146
|
|
|
$this->set($key, $value); |
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
|