1 | <?php declare(strict_types=1); |
||
20 | class State { |
||
21 | // -------------------------------------------------------------------------- |
||
22 | // ! SQL Clause Strings |
||
23 | // -------------------------------------------------------------------------- |
||
24 | |||
25 | /** |
||
26 | * Compiled 'select' clause |
||
27 | * @var string |
||
28 | */ |
||
29 | protected $selectString = ''; |
||
30 | |||
31 | /** |
||
32 | * Compiled 'from' clause |
||
33 | * @var string |
||
34 | */ |
||
35 | protected $fromString = ''; |
||
36 | |||
37 | /** |
||
38 | * Compiled arguments for insert / update |
||
39 | * @var string |
||
40 | */ |
||
41 | protected $setString = ''; |
||
42 | |||
43 | /** |
||
44 | * Order by clause |
||
45 | * @var string |
||
46 | */ |
||
47 | protected $orderString = ''; |
||
48 | |||
49 | /** |
||
50 | * Group by clause |
||
51 | * @var string |
||
52 | */ |
||
53 | protected $groupString = ''; |
||
54 | |||
55 | // -------------------------------------------------------------------------- |
||
56 | // ! SQL Clause Arrays |
||
57 | // -------------------------------------------------------------------------- |
||
58 | |||
59 | /** |
||
60 | * Keys for insert/update statement |
||
61 | * @var array |
||
62 | */ |
||
63 | protected $setArrayKeys = []; |
||
64 | |||
65 | /** |
||
66 | * Key/val pairs for order by clause |
||
67 | * @var array |
||
68 | */ |
||
69 | protected $orderArray = []; |
||
70 | |||
71 | /** |
||
72 | * Key/val pairs for group by clause |
||
73 | * @var array |
||
74 | */ |
||
75 | protected $groupArray = []; |
||
76 | |||
77 | // -------------------------------------------------------------------------- |
||
78 | // ! Other Class vars |
||
79 | // -------------------------------------------------------------------------- |
||
80 | |||
81 | /** |
||
82 | * Values to apply to prepared statements |
||
83 | * @var array |
||
84 | */ |
||
85 | protected $values = []; |
||
86 | |||
87 | /** |
||
88 | * Values to apply to where clauses in prepared statements |
||
89 | * @var array |
||
90 | */ |
||
91 | protected $whereValues = []; |
||
92 | |||
93 | /** |
||
94 | * Value for limit string |
||
95 | * @var integer |
||
96 | */ |
||
97 | protected $limit; |
||
98 | |||
99 | /** |
||
100 | * Value for offset in limit string |
||
101 | * @var string|false |
||
102 | */ |
||
103 | protected $offset = FALSE; |
||
104 | |||
105 | /** |
||
106 | * Query component order mapping |
||
107 | * for complex select queries |
||
108 | * |
||
109 | * Format: |
||
110 | * [ |
||
111 | * 'type' => 'where', |
||
112 | * 'conjunction' => ' AND ', |
||
113 | * 'string' => 'k=?' |
||
114 | * ] |
||
115 | * |
||
116 | * @var array |
||
117 | */ |
||
118 | protected $queryMap = []; |
||
119 | |||
120 | /** |
||
121 | * Map for having clause |
||
122 | * @var array |
||
123 | */ |
||
124 | protected $havingMap = []; |
||
125 | |||
126 | /** |
||
127 | * @param string $str |
||
128 | * @return State |
||
129 | */ |
||
130 | public function setSelectString(string $str): self |
||
135 | |||
136 | /** |
||
137 | * @return string |
||
138 | */ |
||
139 | public function getSelectString(): string |
||
143 | |||
144 | /** |
||
145 | * @param string $str |
||
146 | * @return State |
||
147 | */ |
||
148 | public function appendSelectString(string $str): self |
||
153 | |||
154 | /** |
||
155 | * @return string |
||
156 | */ |
||
157 | public function getFromString(): string |
||
161 | |||
162 | /** |
||
163 | * @param string $fromString |
||
164 | * @return State |
||
165 | */ |
||
166 | public function setFromString(string $fromString): self |
||
171 | |||
172 | /** |
||
173 | * @return string |
||
174 | */ |
||
175 | public function getSetString(): string |
||
179 | |||
180 | /** |
||
181 | * @param string $setString |
||
182 | * @return State |
||
183 | */ |
||
184 | public function setSetString(string $setString): self |
||
189 | |||
190 | /** |
||
191 | * @return string |
||
192 | */ |
||
193 | public function getOrderString(): string |
||
197 | |||
198 | /** |
||
199 | * @param string $orderString |
||
200 | * @return State |
||
201 | */ |
||
202 | public function setOrderString(string $orderString): self |
||
207 | |||
208 | /** |
||
209 | * @return string |
||
210 | */ |
||
211 | public function getGroupString(): string |
||
215 | |||
216 | /** |
||
217 | * @param string $groupString |
||
218 | * @return State |
||
219 | */ |
||
220 | public function setGroupString(string $groupString): self |
||
225 | |||
226 | /** |
||
227 | * @return array |
||
228 | */ |
||
229 | public function getSetArrayKeys(): array |
||
233 | |||
234 | /** |
||
235 | * @param array $setArrayKeys |
||
236 | * @return State |
||
237 | */ |
||
238 | public function appendSetArrayKeys(array $setArrayKeys): self |
||
243 | |||
244 | /** |
||
245 | * @param array $setArrayKeys |
||
246 | * @return State |
||
247 | */ |
||
248 | public function setSetArrayKeys(array $setArrayKeys): self |
||
253 | |||
254 | /** |
||
255 | * @return array |
||
256 | */ |
||
257 | public function getOrderArray(): array |
||
261 | |||
262 | /** |
||
263 | * @param string $key |
||
264 | * @param mixed $orderArray |
||
265 | * @return State |
||
266 | */ |
||
267 | public function setOrderArray(string $key, $orderArray): self |
||
272 | |||
273 | /** |
||
274 | * @return array |
||
275 | */ |
||
276 | public function getGroupArray(): array |
||
280 | |||
281 | /** |
||
282 | * @param array $groupArray |
||
283 | * @return State |
||
284 | */ |
||
285 | public function setGroupArray(array $groupArray): self |
||
290 | |||
291 | /** |
||
292 | * @param string $groupArray |
||
293 | * @return State |
||
294 | */ |
||
295 | public function appendGroupArray(string $groupArray): self |
||
300 | |||
301 | /** |
||
302 | * @return array |
||
303 | */ |
||
304 | public function getValues(): array |
||
308 | |||
309 | /** |
||
310 | * @param array $values |
||
311 | * @return State |
||
312 | */ |
||
313 | public function appendValues(array $values): self |
||
318 | |||
319 | /** |
||
320 | * @return array |
||
321 | */ |
||
322 | public function getWhereValues(): array |
||
326 | |||
327 | /** |
||
328 | * @param mixed $val |
||
329 | * @return State |
||
330 | */ |
||
331 | public function appendWhereValues($val): self |
||
346 | |||
347 | /** |
||
348 | * @return int |
||
349 | */ |
||
350 | public function getLimit(): ?int |
||
354 | |||
355 | /** |
||
356 | * @param int $limit |
||
357 | * @return State |
||
358 | */ |
||
359 | public function setLimit(int $limit): self |
||
364 | |||
365 | /** |
||
366 | * @return string|false |
||
367 | */ |
||
368 | public function getOffset() |
||
372 | |||
373 | /** |
||
374 | * @param string|false $offset |
||
375 | * @return State |
||
376 | */ |
||
377 | public function setOffset($offset): self |
||
382 | |||
383 | /** |
||
384 | * @return array |
||
385 | */ |
||
386 | public function getQueryMap(): array |
||
390 | |||
391 | /** |
||
392 | * Add an additional set of mapping pairs to a internal map |
||
393 | * |
||
394 | * @param string $conjunction |
||
395 | * @param string $string |
||
396 | * @param string $type |
||
397 | * @return State |
||
398 | */ |
||
399 | public function appendMap(string $conjunction = '', string $string = '', string $type = ''): self |
||
408 | |||
409 | /** |
||
410 | * @return array |
||
411 | */ |
||
412 | public function getHavingMap(): array |
||
416 | |||
417 | /** |
||
418 | * @param array $item |
||
419 | * @return State |
||
420 | */ |
||
421 | public function appendHavingMap(array $item): self |
||
426 | } |
||
427 |