1 | <?php namespace Arcanedev\Settings\Stores; |
||
15 | class DatabaseStore extends Store implements StoreContract |
||
16 | { |
||
17 | /* ------------------------------------------------------------------------------------------------ |
||
18 | | Properties |
||
19 | | ------------------------------------------------------------------------------------------------ |
||
20 | */ |
||
21 | /** |
||
22 | * The database connection instance. |
||
23 | * |
||
24 | * @var \Illuminate\Database\Connection |
||
25 | */ |
||
26 | protected $connection; |
||
27 | |||
28 | /** |
||
29 | * The table to query from. |
||
30 | * |
||
31 | * @var string |
||
32 | */ |
||
33 | protected $table; |
||
34 | |||
35 | /** |
||
36 | * Any query constraints that should be applied. |
||
37 | * |
||
38 | * @var Closure|null |
||
39 | */ |
||
40 | protected $queryConstraint; |
||
41 | |||
42 | /** |
||
43 | * Any extra columns that should be added to the rows. |
||
44 | * |
||
45 | * @var array |
||
46 | */ |
||
47 | protected $extraColumns = []; |
||
48 | |||
49 | /* ------------------------------------------------------------------------------------------------ |
||
50 | | Constructor |
||
51 | | ------------------------------------------------------------------------------------------------ |
||
52 | */ |
||
53 | /** |
||
54 | * Make the Database store instance. |
||
55 | * |
||
56 | * @param \Illuminate\Database\Connection $connection |
||
57 | * @param string $table |
||
58 | */ |
||
59 | 24 | public function __construct(Connection $connection, $table = null) |
|
64 | |||
65 | /* ------------------------------------------------------------------------------------------------ |
||
66 | | Getters & Setters |
||
67 | | ------------------------------------------------------------------------------------------------ |
||
68 | */ |
||
69 | /** |
||
70 | * Set the database connection. |
||
71 | * |
||
72 | * @param \Illuminate\Database\Connection $connection |
||
73 | * |
||
74 | * @return self |
||
75 | */ |
||
76 | 24 | public function setConnection(Connection $connection) |
|
82 | |||
83 | /** |
||
84 | * Set the table to query from. |
||
85 | * |
||
86 | * @param string $table |
||
87 | * |
||
88 | * @return self |
||
89 | */ |
||
90 | 24 | public function setTable($table) |
|
96 | |||
97 | /** |
||
98 | * Set the query constraint. |
||
99 | * |
||
100 | * @param \Closure $callback |
||
101 | * |
||
102 | * @return self |
||
103 | */ |
||
104 | public function setConstraint(Closure $callback) |
||
112 | |||
113 | /** |
||
114 | * Set extra columns to be added to the rows. |
||
115 | * |
||
116 | * @param array $columns |
||
117 | * |
||
118 | * @return self |
||
119 | */ |
||
120 | public function setExtraColumns(array $columns) |
||
126 | |||
127 | /* ------------------------------------------------------------------------------------------------ |
||
128 | | Main Functions |
||
129 | | ------------------------------------------------------------------------------------------------ |
||
130 | */ |
||
131 | /** |
||
132 | * {@inheritdoc} |
||
133 | */ |
||
134 | 6 | public function forget($key) |
|
156 | |||
157 | /* ------------------------------------------------------------------------------------------------ |
||
158 | | Other Functions |
||
159 | | ------------------------------------------------------------------------------------------------ |
||
160 | */ |
||
161 | /** |
||
162 | * {@inheritdoc} |
||
163 | */ |
||
164 | 21 | protected function read() |
|
168 | |||
169 | /** |
||
170 | * {@inheritdoc} |
||
171 | */ |
||
172 | 15 | protected function write(array $data) |
|
205 | |||
206 | /** |
||
207 | * Parse data coming from the database. |
||
208 | * |
||
209 | * @param array $data |
||
210 | * |
||
211 | * @return array |
||
212 | */ |
||
213 | 21 | protected function parseReadData($data) |
|
237 | |||
238 | /** |
||
239 | * Transforms settings data into an array ready to be insterted into the |
||
240 | * database. Call array_dot on a multidimensional array before passing it |
||
241 | * into this method! |
||
242 | * |
||
243 | * @param array $data Call array_dot on a multidimensional array before passing it into this method! |
||
244 | * |
||
245 | * @return array |
||
246 | */ |
||
247 | 15 | protected function prepareInsertData(array $data) |
|
259 | |||
260 | /** |
||
261 | * Create a new query builder instance. |
||
262 | * |
||
263 | * @param $insert boolean Whether the query is an insert or not. |
||
264 | * |
||
265 | * @return \Illuminate\Database\Query\Builder |
||
266 | */ |
||
267 | 21 | protected function newQuery($insert = false) |
|
285 | } |
||
286 |