1 | <?php namespace Arcanesoft\Settings\Stores; |
||
13 | class EloquentStore |
||
14 | { |
||
15 | /* ------------------------------------------------------------------------------------------------ |
||
16 | | Properties |
||
17 | | ------------------------------------------------------------------------------------------------ |
||
18 | */ |
||
19 | /** |
||
20 | * The Setting Eloquent Model. |
||
21 | * |
||
22 | * @var \Arcanesoft\Settings\Models\Setting |
||
23 | */ |
||
24 | protected $model; |
||
25 | |||
26 | /** |
||
27 | * The cache repository. |
||
28 | * |
||
29 | * @var \Illuminate\Contracts\Cache\Repository |
||
30 | */ |
||
31 | protected $cache; |
||
32 | |||
33 | /** |
||
34 | * @var \Illuminate\Database\Eloquent\Collection |
||
35 | */ |
||
36 | protected $saved; |
||
37 | |||
38 | /* ------------------------------------------------------------------------------------------------ |
||
39 | | Constructor |
||
40 | | ------------------------------------------------------------------------------------------------ |
||
41 | */ |
||
42 | /** |
||
43 | * SettingsManager constructor. |
||
44 | * |
||
45 | * @param \Arcanesoft\Settings\Models\Setting $model |
||
46 | * @param \Illuminate\Contracts\Cache\Repository $cache |
||
47 | */ |
||
48 | 30 | public function __construct(Setting $model, Cache $cache) |
|
53 | |||
54 | /* ------------------------------------------------------------------------------------------------ |
||
55 | | Getters & Setters |
||
56 | | ------------------------------------------------------------------------------------------------ |
||
57 | */ |
||
58 | /** |
||
59 | * Get the cache key. |
||
60 | * |
||
61 | * @return string |
||
62 | */ |
||
63 | 30 | protected function getCacheKey() |
|
67 | |||
68 | /** |
||
69 | * Check if cache is enabled. |
||
70 | * |
||
71 | * @return bool |
||
72 | */ |
||
73 | 30 | protected function isCached() |
|
77 | |||
78 | /** |
||
79 | * Get the config value by key. |
||
80 | * |
||
81 | * @param string $key |
||
82 | * @param mixed $default |
||
83 | * |
||
84 | * @return mixed |
||
85 | */ |
||
86 | 30 | private function config($key, $default = null) |
|
90 | |||
91 | /** |
||
92 | * Set the saved entries. |
||
93 | * |
||
94 | * @param \Illuminate\Database\Eloquent\Collection $saved |
||
95 | * |
||
96 | * @return self |
||
97 | */ |
||
98 | 21 | private function setSaved(EloquentCollection $saved) |
|
104 | |||
105 | /* ------------------------------------------------------------------------------------------------ |
||
106 | | Main Functions |
||
107 | | ------------------------------------------------------------------------------------------------ |
||
108 | */ |
||
109 | /** |
||
110 | * Get all the setting entries. |
||
111 | * |
||
112 | * @return \Illuminate\Database\Eloquent\Collection |
||
113 | */ |
||
114 | 30 | public function all() |
|
122 | |||
123 | /** |
||
124 | * Save the changes. |
||
125 | * |
||
126 | * @param \Illuminate\Database\Eloquent\Collection $saved |
||
127 | * @param array $changes |
||
128 | */ |
||
129 | 21 | public function save($saved, array $changes) |
|
140 | |||
141 | /* ------------------------------------------------------------------------------------------------ |
||
142 | | Other Functions |
||
143 | | ------------------------------------------------------------------------------------------------ |
||
144 | */ |
||
145 | /** |
||
146 | * Save the inserted entries. |
||
147 | * |
||
148 | * @param array $inserted |
||
149 | */ |
||
150 | 21 | private function saveInserted(array $inserted) |
|
158 | |||
159 | /** |
||
160 | * Save the updated entries. |
||
161 | * |
||
162 | * @param array $updated |
||
163 | */ |
||
164 | 21 | private function saveUpdated(array $updated) |
|
174 | |||
175 | /** |
||
176 | * Save the deleted entries. |
||
177 | * |
||
178 | * @param array $deleted |
||
179 | */ |
||
180 | 21 | private function saveDeleted(array $deleted) |
|
188 | |||
189 | /** |
||
190 | * Get the first saved entry. |
||
191 | * |
||
192 | * @param string $domain |
||
193 | * @param string $key |
||
194 | * |
||
195 | * @return \Arcanesoft\Settings\Models\Setting |
||
196 | */ |
||
197 | 12 | private function getSavedOne($domain, $key) |
|
201 | } |
||
202 |