1 | <?php namespace Arcanedev\Settings\Stores; |
||
15 | class DatabaseStore extends Store implements StoreContract |
||
16 | { |
||
17 | /* ------------------------------------------------------------------------------------------------ |
||
18 | | Properties |
||
19 | | ------------------------------------------------------------------------------------------------ |
||
20 | */ |
||
21 | /** @var \Arcanedev\Settings\Models\Setting */ |
||
22 | protected $model; |
||
23 | |||
24 | /** |
||
25 | * Any query constraints that should be applied. |
||
26 | * |
||
27 | * @var Closure|null |
||
28 | */ |
||
29 | protected $queryConstraint; |
||
30 | |||
31 | /** |
||
32 | * Any extra columns that should be added to the rows. |
||
33 | * |
||
34 | * @var array |
||
35 | */ |
||
36 | protected $extraColumns = []; |
||
37 | |||
38 | /* ------------------------------------------------------------------------------------------------ |
||
39 | | Constructor |
||
40 | | ------------------------------------------------------------------------------------------------ |
||
41 | */ |
||
42 | /** |
||
43 | * Make the Database store instance. |
||
44 | * |
||
45 | * @param string $connection |
||
46 | * @param string $table |
||
47 | */ |
||
48 | 24 | public function __construct($connection, $table = null) |
|
54 | |||
55 | /* ------------------------------------------------------------------------------------------------ |
||
56 | | Getters & Setters |
||
57 | | ------------------------------------------------------------------------------------------------ |
||
58 | */ |
||
59 | /** |
||
60 | * Set the database connection. |
||
61 | * |
||
62 | * @param string $connection |
||
63 | * |
||
64 | * @return self |
||
65 | */ |
||
66 | 24 | public function setConnection($connection) |
|
72 | |||
73 | /** |
||
74 | * Set the table to query from. |
||
75 | * |
||
76 | * @param string $table |
||
77 | * |
||
78 | * @return self |
||
79 | */ |
||
80 | 24 | public function setTable($table) |
|
86 | |||
87 | /** |
||
88 | * Set the query constraint. |
||
89 | * |
||
90 | * @param \Closure $callback |
||
91 | * |
||
92 | * @return self |
||
93 | */ |
||
94 | public function setConstraint(Closure $callback) |
||
102 | |||
103 | /** |
||
104 | * Set extra columns to be added to the rows. |
||
105 | * |
||
106 | * @param array $columns |
||
107 | * |
||
108 | * @return self |
||
109 | */ |
||
110 | public function setExtraColumns(array $columns) |
||
116 | |||
117 | /* ------------------------------------------------------------------------------------------------ |
||
118 | | Main Functions |
||
119 | | ------------------------------------------------------------------------------------------------ |
||
120 | */ |
||
121 | /** |
||
122 | * {@inheritdoc} |
||
123 | */ |
||
124 | 6 | public function forget($key) |
|
146 | |||
147 | /* ------------------------------------------------------------------------------------------------ |
||
148 | | Other Functions |
||
149 | | ------------------------------------------------------------------------------------------------ |
||
150 | */ |
||
151 | /** |
||
152 | * {@inheritdoc} |
||
153 | */ |
||
154 | 21 | protected function read() |
|
165 | |||
166 | /** |
||
167 | * {@inheritdoc} |
||
168 | */ |
||
169 | 15 | protected function write(array $data) |
|
177 | |||
178 | /* ------------------------------------------------------------------------------------------------ |
||
179 | | CRUD Functions |
||
180 | | ------------------------------------------------------------------------------------------------ |
||
181 | */ |
||
182 | /** |
||
183 | * Prepare settings data. |
||
184 | * |
||
185 | * @param array $data |
||
186 | * |
||
187 | * @return array |
||
188 | */ |
||
189 | 15 | private function prepareData(array $data) |
|
206 | |||
207 | /** |
||
208 | * Update settings data. |
||
209 | * |
||
210 | * @param array $updates |
||
211 | */ |
||
212 | 15 | private function updateSettings($updates) |
|
218 | |||
219 | /** |
||
220 | * Insert settings data. |
||
221 | * |
||
222 | * @param array $inserts |
||
223 | */ |
||
224 | 15 | private function insertSettings(array $inserts) |
|
239 | |||
240 | /** |
||
241 | * Delete settings data. |
||
242 | * |
||
243 | * @param array $deletes |
||
244 | */ |
||
245 | 15 | private function deleteSettings(array $deletes) |
|
253 | |||
254 | /** |
||
255 | * Create a new query builder instance. |
||
256 | * |
||
257 | * @param $insert bool Whether the query is an insert or not. |
||
258 | * |
||
259 | * @return \Arcanedev\Settings\Models\Setting |
||
260 | */ |
||
261 | 15 | private function model($insert = false) |
|
279 | } |
||
280 |