1 | <?php |
||
24 | class Where |
||
25 | { |
||
26 | public $stack = []; |
||
27 | public $element; |
||
28 | public $values = []; |
||
29 | public $operator; |
||
30 | |||
31 | /** |
||
32 | * create |
||
33 | * |
||
34 | * A constructor you can chain from. |
||
35 | * |
||
36 | * @param string $element |
||
37 | * @param array $values |
||
38 | * @return Where |
||
39 | */ |
||
40 | public static function create($element = null, array $values = []) |
||
44 | |||
45 | /** |
||
46 | * createWhereIn |
||
47 | * |
||
48 | * Create an escaped IN clause. |
||
49 | * |
||
50 | * @param string $element |
||
51 | * @param array $values |
||
52 | * @return Where |
||
53 | */ |
||
54 | public static function createWhereIn($element, array $values) |
||
58 | |||
59 | /** |
||
60 | * createWhereNotIn |
||
61 | * |
||
62 | * Create an escaped NOT IN clause. |
||
63 | * |
||
64 | * @param string $element |
||
65 | * @param array $values |
||
66 | * @return Where |
||
67 | */ |
||
68 | public static function createWhereNotIn($element, array $values) |
||
72 | |||
73 | /** |
||
74 | * createGroupCondition |
||
75 | * |
||
76 | * Create a Where instance with multiple escaped parameters. This is mainly |
||
77 | * useful for IN or NOT IN clauses. |
||
78 | * |
||
79 | * @param string $element |
||
80 | * @param string $operation |
||
81 | * @param array $values |
||
82 | * @return Where |
||
83 | */ |
||
84 | public static function createGroupCondition($element, $operation, array $values) |
||
96 | |||
97 | /** |
||
98 | * extractValues |
||
99 | * |
||
100 | * Extract values with consistent keys. |
||
101 | * |
||
102 | * @param array $values |
||
103 | * @return array |
||
104 | */ |
||
105 | protected static function extractValues(array $values) |
||
115 | |||
116 | /** |
||
117 | * escapeSet |
||
118 | * |
||
119 | * Create an array of escaped strings from a value set. |
||
120 | * |
||
121 | * @param array $values |
||
122 | * @return array |
||
123 | */ |
||
124 | protected static function escapeSet(array $values) |
||
139 | |||
140 | /** |
||
141 | * __construct |
||
142 | * |
||
143 | * @param string $element (optional) |
||
144 | * @param array $values (optional) |
||
145 | */ |
||
146 | public function __construct($element = null, array $values = []) |
||
153 | |||
154 | /** |
||
155 | * setOperator |
||
156 | * |
||
157 | * is it an AND or an OR ? |
||
158 | * or something else. |
||
159 | * XOR can be expressed as "A = !B" |
||
160 | * |
||
161 | * @param string $operator |
||
162 | * @return Where |
||
163 | */ |
||
164 | public function setOperator($operator) |
||
170 | |||
171 | /** |
||
172 | * isEmpty |
||
173 | * |
||
174 | * is it a fresh brand new object ? |
||
175 | * |
||
176 | * @return boolean |
||
177 | */ |
||
178 | public function isEmpty() |
||
182 | |||
183 | /** |
||
184 | * transmute |
||
185 | * |
||
186 | * Absorbing another Where instance. |
||
187 | * |
||
188 | * @param Where $where |
||
189 | * @return Where $this |
||
190 | */ |
||
191 | private function transmute(Where $where) |
||
198 | |||
199 | /** |
||
200 | * addWhere |
||
201 | * |
||
202 | * You can add a new WHERE clause with your own operator. |
||
203 | * |
||
204 | * @param mixed $element |
||
205 | * @param array $values |
||
206 | * @param string $operator |
||
207 | * @return Where |
||
208 | */ |
||
209 | public function addWhere($element, array $values, $operator) |
||
246 | |||
247 | /** |
||
248 | * andWhere |
||
249 | * |
||
250 | * Or use a ready to use AND where clause. |
||
251 | * |
||
252 | * @param mixed $element |
||
253 | * @param array $values |
||
254 | * @return Where |
||
255 | */ |
||
256 | public function andWhere($element, array $values = []) |
||
260 | |||
261 | /** |
||
262 | * orWhere |
||
263 | * |
||
264 | * @param mixed $element |
||
265 | * @param array $values |
||
266 | * @return Where |
||
267 | */ |
||
268 | public function orWhere($element, array $values = []) |
||
272 | |||
273 | /** |
||
274 | * setStack |
||
275 | * |
||
276 | * @param array $stack |
||
277 | * @return Where |
||
278 | */ |
||
279 | public function setStack(array $stack) |
||
285 | |||
286 | /** |
||
287 | * __toString |
||
288 | * |
||
289 | * where your SQL statement is built. |
||
290 | * |
||
291 | * @return string |
||
292 | */ |
||
293 | public function __toString() |
||
297 | |||
298 | /** |
||
299 | * hasElement |
||
300 | * |
||
301 | * @return boolean |
||
302 | */ |
||
303 | public function hasElement() |
||
307 | |||
308 | /** |
||
309 | * getElement |
||
310 | * |
||
311 | * @return string |
||
312 | */ |
||
313 | public function getElement() |
||
317 | |||
318 | /** |
||
319 | * parse |
||
320 | * |
||
321 | * @return string |
||
322 | */ |
||
323 | protected function parse() |
||
336 | |||
337 | /** |
||
338 | * getValues |
||
339 | * |
||
340 | * Get all the values back for the prepared statement. |
||
341 | * |
||
342 | * @return array |
||
343 | */ |
||
344 | public function getValues() |
||
362 | } |
||
363 |