1
1
<?php
2
2
/**
3
3
* @link https://github.com/yii2tech
4
+ *
4
5
* @copyright Copyright (c) 2015 Yii2tech
5
6
* @license [New BSD License](http://www.opensource.org/licenses/bsd-license.php)
6
7
*/
19
20
*
20
21
* @author Paul Klimov <[email protected] >
21
22
* @author Igor Chepurnoy <[email protected] >
23
+ *
22
24
* @since 1.0
23
25
*/
24
26
class QueryProcessor extends Component
@@ -65,10 +67,10 @@ public function process($query)
65
67
/**
66
68
* Applies sort for given data.
67
69
*
68
- * @param array $data raw data.
69
- * @param array|null $orderBy order by.
70
+ * @param array $data raw data
71
+ * @param array|null $orderBy order by
70
72
*
71
- * @return array sorted data.
73
+ * @return array sorted data
72
74
*/
73
75
protected function applyOrderBy (array $ data , $ orderBy )
74
76
{
@@ -82,11 +84,11 @@ protected function applyOrderBy(array $data, $orderBy)
82
84
/**
83
85
* Applies limit and offset for given data.
84
86
*
85
- * @param array $data raw data.
86
- * @param integer |null $limit limit value.
87
- * @param integer |null $offset offset value.
87
+ * @param array $data raw data
88
+ * @param int |null $limit limit value
89
+ * @param int |null $offset offset value
88
90
*
89
- * @return array data.
91
+ * @return array data
90
92
*/
91
93
protected function applyLimit (array $ data , $ limit , $ offset )
92
94
{
@@ -108,10 +110,10 @@ protected function applyLimit(array $data, $limit, $offset)
108
110
/**
109
111
* Applies where conditions.
110
112
*
111
- * @param array $data raw data.
112
- * @param array|null $where where conditions.
113
+ * @param array $data raw data
114
+ * @param array|null $where where conditions
113
115
*
114
- * @return array data.
116
+ * @return array data
115
117
*/
116
118
protected function applyWhere (array $ data , $ where )
117
119
{
@@ -121,10 +123,10 @@ protected function applyWhere(array $data, $where)
121
123
/**
122
124
* Applies filter conditions.
123
125
*
124
- * @param array $data data to be filtered.
125
- * @param array $condition filter condition.
126
+ * @param array $data data to be filtered
127
+ * @param array $condition filter condition
126
128
*
127
- * @return array filtered data.
129
+ * @return array filtered data
128
130
*
129
131
* @throws InvalidParamException
130
132
*/
@@ -146,6 +148,7 @@ protected function filterCondition(array $data, $condition)
146
148
throw new InvalidParamException ("Invalid condition filter ' {$ operator }' " );
147
149
}
148
150
array_shift ($ condition );
151
+
149
152
return $ this ->$ method ($ data , $ operator , $ condition );
150
153
} else {
151
154
return $ this ->filterHashCondition ($ data , $ condition );
@@ -156,7 +159,7 @@ protected function filterCondition(array $data, $condition)
156
159
* Applies a condition based on column-value pairs.
157
160
*
158
161
* @param array $data data to be filtered
159
- * @param array $condition the condition specification.
162
+ * @param array $condition the condition specification
160
163
*
161
164
* @return array filtered data
162
165
*/
@@ -167,7 +170,7 @@ protected function filterHashCondition(array $data, $condition)
167
170
$ data = $ this ->filterInCondition ($ data , 'IN ' , [$ column , $ value ]);
168
171
} else {
169
172
$ data = array_filter ($ data , function ($ row ) use ($ column , $ value ) {
170
- return ( $ row [$ column ] == $ value) ;
173
+ return $ row [$ column ] == $ value ;
171
174
});
172
175
}
173
176
}
@@ -179,8 +182,8 @@ protected function filterHashCondition(array $data, $condition)
179
182
* Applies 2 or more conditions using 'AND' logic.
180
183
*
181
184
* @param array $data data to be filtered
182
- * @param string $operator operator.
183
- * @param array $operands conditions to be united.
185
+ * @param string $operator operator
186
+ * @param array $operands conditions to be united
184
187
*
185
188
* @return array filtered data
186
189
*/
@@ -198,9 +201,9 @@ protected function filterAndCondition(array $data, $operator, $operands)
198
201
/**
199
202
* Applies 2 or more conditions using 'OR' logic.
200
203
*
201
- * @param array $data data to be filtered.
202
- * @param string $operator operator.
203
- * @param array $operands conditions to be united.
204
+ * @param array $data data to be filtered
205
+ * @param string $operator operator
206
+ * @param array $operands conditions to be united
204
207
*
205
208
* @return array filtered data
206
209
*/
@@ -231,13 +234,13 @@ protected function filterOrCondition(array $data, $operator, $operands)
231
234
/**
232
235
* Inverts a filter condition.
233
236
*
234
- * @param array $data data to be filtered.
235
- * @param string $operator operator.
236
- * @param array $operands operands to be inverted.
237
+ * @param array $data data to be filtered
238
+ * @param string $operator operator
239
+ * @param array $operands operands to be inverted
237
240
*
238
- * @return array filtered data.
241
+ * @return array filtered data
239
242
*
240
- * @throws InvalidParamException if wrong number of operands have been given.
243
+ * @throws InvalidParamException if wrong number of operands have been given
241
244
*/
242
245
protected function filterNotCondition (array $ data , $ operator , $ operands )
243
246
{
@@ -268,14 +271,14 @@ protected function filterNotCondition(array $data, $operator, $operands)
268
271
/**
269
272
* Applies `BETWEEN` condition.
270
273
*
271
- * @param array $data data to be filtered.
272
- * @param string $operator operator.
274
+ * @param array $data data to be filtered
275
+ * @param string $operator operator
273
276
* @param array $operands the first operand is the column name. The second and third operands
274
- * describe the interval that column value should be in.
277
+ * describe the interval that column value should be in
275
278
*
276
- * @return array filtered data.
279
+ * @return array filtered data
277
280
*
278
- * @throws InvalidParamException if wrong number of operands have been given.
281
+ * @throws InvalidParamException if wrong number of operands have been given
279
282
*/
280
283
protected function filterBetweenCondition (array $ data , $ operator , $ operands )
281
284
{
@@ -287,26 +290,26 @@ protected function filterBetweenCondition(array $data, $operator, $operands)
287
290
288
291
if (strncmp ('NOT ' , $ operator , 3 ) === 0 ) {
289
292
return array_filter ($ data , function ($ row ) use ($ column , $ value1 , $ value2 ) {
290
- return ( $ row [$ column ] < $ value1 || $ row [$ column ] > $ value2) ;
293
+ return $ row [$ column ] < $ value1 || $ row [$ column ] > $ value2 ;
291
294
});
292
295
}
293
296
294
297
return array_filter ($ data , function ($ row ) use ($ column , $ value1 , $ value2 ) {
295
- return ( $ row [$ column ] >= $ value1 && $ row [$ column ] <= $ value2) ;
298
+ return $ row [$ column ] >= $ value1 && $ row [$ column ] <= $ value2 ;
296
299
});
297
300
}
298
301
299
302
/**
300
303
* Applies 'IN' condition.
301
304
*
302
- * @param array $data data to be filtered.
303
- * @param string $operator operator.
305
+ * @param array $data data to be filtered
306
+ * @param string $operator operator
304
307
* @param array $operands the first operand is the column name.
305
- * The second operand is an array of values that column value should be among.
308
+ * The second operand is an array of values that column value should be among
306
309
*
307
- * @return array filtered data.
310
+ * @return array filtered data
308
311
*
309
- * @throws InvalidParamException if wrong number of operands have been given.
312
+ * @throws InvalidParamException if wrong number of operands have been given
310
313
*/
311
314
protected function filterInCondition (array $ data , $ operator , $ operands )
312
315
{
@@ -350,14 +353,14 @@ protected function filterInCondition(array $data, $operator, $operands)
350
353
/**
351
354
* Applies 'LIKE' condition.
352
355
*
353
- * @param array $data data to be filtered.
354
- * @param string $operator operator.
356
+ * @param array $data data to be filtered
357
+ * @param string $operator operator
355
358
* @param array $operands the first operand is the column name. The second operand is a single value
356
- * or an array of values that column value should be compared with.
359
+ * or an array of values that column value should be compared with
357
360
*
358
- * @return array filtered data.
361
+ * @return array filtered data
359
362
*
360
- * @throws InvalidParamException if wrong number of operands have been given.
363
+ * @throws InvalidParamException if wrong number of operands have been given
361
364
*/
362
365
protected function filterLikeCondition (array $ data , $ operator , $ operands )
363
366
{
@@ -386,6 +389,7 @@ protected function filterLikeCondition(array $data, $operator, $operands)
386
389
return true ;
387
390
}
388
391
}
392
+
389
393
return false ;
390
394
});
391
395
}
@@ -396,6 +400,7 @@ protected function filterLikeCondition(array $data, $operator, $operands)
396
400
return false ;
397
401
}
398
402
}
403
+
399
404
return true ;
400
405
});
401
406
}
@@ -411,6 +416,7 @@ protected function filterLikeCondition(array $data, $operator, $operands)
411
416
return true ;
412
417
}
413
418
}
419
+
414
420
return false ;
415
421
});
416
422
}
@@ -421,7 +427,8 @@ protected function filterLikeCondition(array $data, $operator, $operands)
421
427
return false ;
422
428
}
423
429
}
430
+
424
431
return true ;
425
432
});
426
433
}
427
- }
434
+ }
0 commit comments