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) |
|
207 | |||
208 | /** |
||
209 | * Parse data coming from the database. |
||
210 | * |
||
211 | * @param array $data |
||
212 | * |
||
213 | * @return array |
||
214 | */ |
||
215 | 21 | protected function parseReadData($data) |
|
239 | |||
240 | /** |
||
241 | * Transforms settings data into an array ready to be insterted into the |
||
242 | * database. Call array_dot on a multidimensional array before passing it |
||
243 | * into this method! |
||
244 | * |
||
245 | * @param array $data Call array_dot on a multidimensional array before passing it into this method! |
||
246 | * |
||
247 | * @return array |
||
248 | */ |
||
249 | 15 | protected function prepareInsertData(array $data) |
|
261 | |||
262 | /** |
||
263 | * Create a new query builder instance. |
||
264 | * |
||
265 | * @param $insert boolean Whether the query is an insert or not. |
||
266 | * |
||
267 | * @return \Illuminate\Database\Query\Builder |
||
268 | */ |
||
269 | 21 | protected function newQuery($insert = false) |
|
287 | } |
||
288 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.