1 | <?php namespace Arcanesoft\Settings; |
||
15 | class SettingsManager implements Contracts\Settings |
||
16 | { |
||
17 | /* ------------------------------------------------------------------------------------------------ |
||
18 | | Properties |
||
19 | | ------------------------------------------------------------------------------------------------ |
||
20 | */ |
||
21 | /** |
||
22 | * The settings data. |
||
23 | * |
||
24 | * @var \Arcanedev\Support\Collection |
||
25 | */ |
||
26 | protected $data; |
||
27 | |||
28 | /** |
||
29 | * Whether the store has changed since it was last loaded. |
||
30 | * |
||
31 | * @var bool |
||
32 | */ |
||
33 | protected $unsaved = false; |
||
34 | |||
35 | /** |
||
36 | * Whether the settings data are loaded. |
||
37 | * |
||
38 | * @var bool |
||
39 | */ |
||
40 | protected $loaded = false; |
||
41 | |||
42 | /** @var \Arcanesoft\Settings\Stores\EloquentStore */ |
||
43 | private $store; |
||
44 | |||
45 | /* ------------------------------------------------------------------------------------------------ |
||
46 | | Constructor |
||
47 | | ------------------------------------------------------------------------------------------------ |
||
48 | */ |
||
49 | /** |
||
50 | * SettingsManager constructor. |
||
51 | * |
||
52 | * @param \Arcanesoft\Settings\Models\Setting $model |
||
53 | * @param \Illuminate\Contracts\Cache\Repository $cache |
||
54 | */ |
||
55 | 40 | public function __construct(Setting $model, Cache $cache) |
|
60 | |||
61 | /* ------------------------------------------------------------------------------------------------ |
||
62 | | Getters & Setters |
||
63 | | ------------------------------------------------------------------------------------------------ |
||
64 | */ |
||
65 | /** |
||
66 | * Get the settings default domain. |
||
67 | * |
||
68 | * @return string |
||
69 | */ |
||
70 | 36 | protected function getDefaultDomain() |
|
74 | |||
75 | /** |
||
76 | * Get the config value by key. |
||
77 | * |
||
78 | * @param string $key |
||
79 | * @param mixed $default |
||
80 | * |
||
81 | * @return mixed |
||
82 | */ |
||
83 | 36 | private function config($key, $default = null) |
|
87 | |||
88 | /* ------------------------------------------------------------------------------------------------ |
||
89 | | Main Functions |
||
90 | | ------------------------------------------------------------------------------------------------ |
||
91 | */ |
||
92 | /** |
||
93 | * Get a setting by key. |
||
94 | * |
||
95 | * @param string $key |
||
96 | * @param mixed|null $default |
||
97 | * |
||
98 | * @return mixed |
||
99 | */ |
||
100 | 24 | public function get($key, $default = null) |
|
108 | |||
109 | /** |
||
110 | * Set a setting. |
||
111 | * |
||
112 | * @param string $key |
||
113 | * @param mixed $value |
||
114 | */ |
||
115 | 32 | public function set($key, $value) |
|
130 | |||
131 | /** |
||
132 | * Check if a setting exists by the key. |
||
133 | * |
||
134 | * @param string $key |
||
135 | * |
||
136 | * @return bool |
||
137 | */ |
||
138 | 24 | public function has($key) |
|
150 | |||
151 | /** |
||
152 | * Get all the setting by a specific domain. |
||
153 | * |
||
154 | * @param string|null $domain |
||
155 | * |
||
156 | * @return array |
||
157 | */ |
||
158 | 20 | public function all($domain = null) |
|
168 | |||
169 | /** |
||
170 | * Delete a setting. |
||
171 | * |
||
172 | * @param string $key |
||
173 | */ |
||
174 | 8 | public function delete($key) |
|
195 | |||
196 | /** |
||
197 | * Reset/Delete all the settings. |
||
198 | * |
||
199 | * @param string|null $domain |
||
200 | */ |
||
201 | 4 | public function reset($domain = null) |
|
211 | |||
212 | /** |
||
213 | * Save the settings. |
||
214 | */ |
||
215 | 28 | public function save() |
|
223 | |||
224 | /** |
||
225 | * Get the changes. |
||
226 | * |
||
227 | * @param \Illuminate\Database\Eloquent\Collection $saved |
||
228 | * |
||
229 | * @return array |
||
230 | */ |
||
231 | 28 | private function getChanges($saved) |
|
243 | |||
244 | /** |
||
245 | * Grab the settings domain name from the key. |
||
246 | * |
||
247 | * @param string $key |
||
248 | * |
||
249 | * @return string |
||
250 | */ |
||
251 | 32 | private function grabDomain(&$key) |
|
261 | |||
262 | /* ------------------------------------------------------------------------------------------------ |
||
263 | | Other Functions |
||
264 | | ------------------------------------------------------------------------------------------------ |
||
265 | */ |
||
266 | /** |
||
267 | * Check if the data is loaded |
||
268 | */ |
||
269 | 36 | private function checkLoaded() |
|
277 | |||
278 | /** |
||
279 | * Load the data. |
||
280 | */ |
||
281 | 36 | private function loadData() |
|
290 | } |
||
291 |