1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* This file is part of the Happyr Doctrine Specification package. |
6
|
|
|
* |
7
|
|
|
* (c) Tobias Nyholm <[email protected]> |
8
|
|
|
* Kacper Gunia <[email protected]> |
9
|
|
|
* Peter Gribanov <[email protected]> |
10
|
|
|
* |
11
|
|
|
* For the full copyright and license information, please view the LICENSE |
12
|
|
|
* file that was distributed with this source code. |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace Happyr\DoctrineSpecification; |
16
|
|
|
|
17
|
|
|
use Happyr\DoctrineSpecification\Filter\Equals; |
18
|
|
|
use Happyr\DoctrineSpecification\Filter\Filter; |
19
|
|
|
use Happyr\DoctrineSpecification\Filter\GreaterOrEqualThan; |
20
|
|
|
use Happyr\DoctrineSpecification\Filter\GreaterThan; |
21
|
|
|
use Happyr\DoctrineSpecification\Filter\In; |
22
|
|
|
use Happyr\DoctrineSpecification\Filter\InstanceOfX; |
23
|
|
|
use Happyr\DoctrineSpecification\Filter\IsNotNull; |
24
|
|
|
use Happyr\DoctrineSpecification\Filter\IsNull; |
25
|
|
|
use Happyr\DoctrineSpecification\Filter\LessOrEqualThan; |
26
|
|
|
use Happyr\DoctrineSpecification\Filter\LessThan; |
27
|
|
|
use Happyr\DoctrineSpecification\Filter\Like; |
28
|
|
|
use Happyr\DoctrineSpecification\Filter\MemberOfX; |
29
|
|
|
use Happyr\DoctrineSpecification\Filter\NotEquals; |
30
|
|
|
use Happyr\DoctrineSpecification\Logic\AndX; |
31
|
|
|
use Happyr\DoctrineSpecification\Logic\Not; |
32
|
|
|
use Happyr\DoctrineSpecification\Logic\OrX; |
33
|
|
|
use Happyr\DoctrineSpecification\Operand\Addition; |
34
|
|
|
use Happyr\DoctrineSpecification\Operand\Alias; |
35
|
|
|
use Happyr\DoctrineSpecification\Operand\CountDistinct; |
36
|
|
|
use Happyr\DoctrineSpecification\Operand\Division; |
37
|
|
|
use Happyr\DoctrineSpecification\Operand\Field; |
38
|
|
|
use Happyr\DoctrineSpecification\Operand\LikePattern; |
39
|
|
|
use Happyr\DoctrineSpecification\Operand\Modulo; |
40
|
|
|
use Happyr\DoctrineSpecification\Operand\Multiplication; |
41
|
|
|
use Happyr\DoctrineSpecification\Operand\Operand; |
42
|
|
|
use Happyr\DoctrineSpecification\Operand\PlatformFunction; |
43
|
|
|
use Happyr\DoctrineSpecification\Operand\Subtraction; |
44
|
|
|
use Happyr\DoctrineSpecification\Operand\Value; |
45
|
|
|
use Happyr\DoctrineSpecification\Operand\Values; |
46
|
|
|
use Happyr\DoctrineSpecification\Query\AddSelect; |
47
|
|
|
use Happyr\DoctrineSpecification\Query\Distinct; |
48
|
|
|
use Happyr\DoctrineSpecification\Query\GroupBy; |
49
|
|
|
use Happyr\DoctrineSpecification\Query\Having; |
50
|
|
|
use Happyr\DoctrineSpecification\Query\IndexBy; |
51
|
|
|
use Happyr\DoctrineSpecification\Query\InnerJoin; |
52
|
|
|
use Happyr\DoctrineSpecification\Query\Join; |
53
|
|
|
use Happyr\DoctrineSpecification\Query\LeftJoin; |
54
|
|
|
use Happyr\DoctrineSpecification\Query\Limit; |
55
|
|
|
use Happyr\DoctrineSpecification\Query\Offset; |
56
|
|
|
use Happyr\DoctrineSpecification\Query\OrderBy; |
57
|
|
|
use Happyr\DoctrineSpecification\Query\QueryModifier; |
58
|
|
|
use Happyr\DoctrineSpecification\Query\Select; |
59
|
|
|
use Happyr\DoctrineSpecification\Query\Selection\SelectAs; |
60
|
|
|
use Happyr\DoctrineSpecification\Query\Selection\SelectEntity; |
61
|
|
|
use Happyr\DoctrineSpecification\Query\Selection\SelectHiddenAs; |
62
|
|
|
use Happyr\DoctrineSpecification\Query\Selection\Selection; |
63
|
|
|
use Happyr\DoctrineSpecification\Query\Slice; |
64
|
|
|
use Happyr\DoctrineSpecification\Result\AsArray; |
65
|
|
|
use Happyr\DoctrineSpecification\Result\AsScalar; |
66
|
|
|
use Happyr\DoctrineSpecification\Result\AsSingleScalar; |
67
|
|
|
use Happyr\DoctrineSpecification\Result\Cache; |
68
|
|
|
use Happyr\DoctrineSpecification\Result\RoundDateTime; |
69
|
|
|
use Happyr\DoctrineSpecification\Specification\CountOf; |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Factory class for the specifications. |
73
|
|
|
* |
74
|
|
|
* @method static PlatformFunction CONCAT($str1, $str2) |
75
|
|
|
* @method static PlatformFunction SUBSTRING($str, $start, $length = null) Return substring of given string. |
76
|
|
|
* @method static PlatformFunction TRIM($str) Trim the string by the given trim char, defaults to whitespaces. |
77
|
|
|
* @method static PlatformFunction LOWER($str) Returns the string lowercased. |
78
|
|
|
* @method static PlatformFunction UPPER($str) Return the upper-case of the given string. |
79
|
|
|
* @method static PlatformFunction IDENTITY($expression, $fieldMapping = null) Retrieve the foreign key column of association of the owning side |
80
|
|
|
* @method static PlatformFunction LENGTH($str) Returns the length of the given string |
81
|
|
|
* @method static PlatformFunction LOCATE($needle, $haystack, $offset = 0) Locate the first occurrence of the substring in the string. |
82
|
|
|
* @method static PlatformFunction ABS($expression) |
83
|
|
|
* @method static PlatformFunction SQRT($q) Return the square-root of q. |
84
|
|
|
* @method static PlatformFunction MOD($a, $b) Return a MOD b. |
85
|
|
|
* @method static PlatformFunction SIZE($collection) Return the number of elements in the specified collection |
86
|
|
|
* @method static PlatformFunction DATE_DIFF($date1, $date2) Calculate the difference in days between date1-date2. |
87
|
|
|
* @method static PlatformFunction BIT_AND($a, $b) |
88
|
|
|
* @method static PlatformFunction BIT_OR($a, $b) |
89
|
|
|
* @method static PlatformFunction MIN($a) |
90
|
|
|
* @method static PlatformFunction MAX($a) |
91
|
|
|
* @method static PlatformFunction AVG($a) |
92
|
|
|
* @method static PlatformFunction SUM($a) |
93
|
|
|
* @method static PlatformFunction COUNT($a) |
94
|
|
|
* @method static PlatformFunction CURRENT_DATE() Return the current date |
95
|
|
|
* @method static PlatformFunction CURRENT_TIME() Returns the current time |
96
|
|
|
* @method static PlatformFunction CURRENT_TIMESTAMP() Returns a timestamp of the current date and time. |
97
|
|
|
* @method static PlatformFunction DATE_ADD($date, $days, $unit) Add the number of days to a given date. (Supported units are DAY, MONTH) |
98
|
|
|
* @method static PlatformFunction DATE_SUB($date, $days, $unit) Substract the number of days from a given date. (Supported units are DAY, MONTH) |
99
|
|
|
*/ |
100
|
|
|
class Spec |
101
|
|
|
{ |
102
|
|
|
/** |
103
|
|
|
* @param string $functionName |
104
|
|
|
* @param mixed[] $arguments |
105
|
|
|
* |
106
|
|
|
* @return PlatformFunction |
107
|
|
|
*/ |
108
|
|
|
public static function __callStatic($functionName, array $arguments = []) |
109
|
|
|
{ |
110
|
|
|
return self::fun($functionName, ...$arguments); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
// Logic |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @param Filter|QueryModifier ...$specs |
117
|
|
|
* |
118
|
|
|
* @return AndX |
119
|
|
|
*/ |
120
|
|
|
public static function andX(...$specs) |
121
|
|
|
{ |
122
|
|
|
return new AndX(...$specs); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @param Filter|QueryModifier ...$specs |
127
|
|
|
* |
128
|
|
|
* @return OrX |
129
|
|
|
*/ |
130
|
|
|
public static function orX(...$specs) |
131
|
|
|
{ |
132
|
|
|
return new OrX(...$specs); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @param Filter $spec |
137
|
|
|
* |
138
|
|
|
* @return Not |
139
|
|
|
*/ |
140
|
|
|
public static function not(Filter $spec) |
141
|
|
|
{ |
142
|
|
|
return new Not($spec); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
// Query modifier |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @param string $field |
149
|
|
|
* @param string $newAlias |
150
|
|
|
* @param string|null $dqlAlias |
151
|
|
|
* |
152
|
|
|
* @return Join |
153
|
|
|
*/ |
154
|
|
|
public static function join($field, $newAlias, $dqlAlias = null) |
155
|
|
|
{ |
156
|
|
|
return new Join($field, $newAlias, $dqlAlias); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* @param string $field |
161
|
|
|
* @param string $newAlias |
162
|
|
|
* @param string|null $dqlAlias |
163
|
|
|
* |
164
|
|
|
* @return LeftJoin |
165
|
|
|
*/ |
166
|
|
|
public static function leftJoin($field, $newAlias, $dqlAlias = null) |
167
|
|
|
{ |
168
|
|
|
return new LeftJoin($field, $newAlias, $dqlAlias); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* @param string $field |
173
|
|
|
* @param string $newAlias |
174
|
|
|
* @param string|null $dqlAlias |
175
|
|
|
* |
176
|
|
|
* @return InnerJoin |
177
|
|
|
*/ |
178
|
|
|
public static function innerJoin($field, $newAlias, $dqlAlias = null) |
179
|
|
|
{ |
180
|
|
|
return new InnerJoin($field, $newAlias, $dqlAlias); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* @param Field|string $field |
185
|
|
|
* @param string|null $dqlAlias |
186
|
|
|
* |
187
|
|
|
* @return IndexBy |
188
|
|
|
*/ |
189
|
|
|
public static function indexBy($field, $dqlAlias = null) |
190
|
|
|
{ |
191
|
|
|
return new IndexBy($field, $dqlAlias); |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* @param int $count |
196
|
|
|
* |
197
|
|
|
* @return Limit |
198
|
|
|
*/ |
199
|
|
|
public static function limit($count) |
200
|
|
|
{ |
201
|
|
|
return new Limit($count); |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* @param int $count |
206
|
|
|
* |
207
|
|
|
* @return Offset |
208
|
|
|
*/ |
209
|
|
|
public static function offset($count) |
210
|
|
|
{ |
211
|
|
|
return new Offset($count); |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* @param int $sliceSize |
216
|
|
|
* @param int $sliceNumber |
217
|
|
|
* |
218
|
|
|
* @return Slice |
219
|
|
|
*/ |
220
|
|
|
public static function slice($sliceSize, $sliceNumber = 0) |
221
|
|
|
{ |
222
|
|
|
return new Slice($sliceSize, $sliceNumber); |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
/** |
226
|
|
|
* @param Field|Alias|string $field |
227
|
|
|
* @param string $order |
228
|
|
|
* @param string|null $dqlAlias |
229
|
|
|
* |
230
|
|
|
* @return OrderBy |
231
|
|
|
*/ |
232
|
|
|
public static function orderBy($field, $order = 'ASC', $dqlAlias = null) |
233
|
|
|
{ |
234
|
|
|
return new OrderBy($field, $order, $dqlAlias); |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* @param Field|Alias|string $field |
239
|
|
|
* @param string|null $dqlAlias |
240
|
|
|
* |
241
|
|
|
* @return GroupBy |
242
|
|
|
*/ |
243
|
|
|
public static function groupBy($field, $dqlAlias = null) |
244
|
|
|
{ |
245
|
|
|
return new GroupBy($field, $dqlAlias); |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
/** |
249
|
|
|
* @return Distinct |
250
|
|
|
*/ |
251
|
|
|
public static function distinct() |
252
|
|
|
{ |
253
|
|
|
return new Distinct(); |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
// Selection |
257
|
|
|
|
258
|
|
|
/** |
259
|
|
|
* @param Selection|string ...$fields |
260
|
|
|
* |
261
|
|
|
* @return Select |
262
|
|
|
*/ |
263
|
|
|
public static function select(...$fields) |
264
|
|
|
{ |
265
|
|
|
return new Select(...$fields); |
266
|
|
|
} |
267
|
|
|
|
268
|
|
|
/** |
269
|
|
|
* @param Selection|string ...$fields |
270
|
|
|
* |
271
|
|
|
* @return AddSelect |
272
|
|
|
*/ |
273
|
|
|
public static function addSelect(...$fields) |
274
|
|
|
{ |
275
|
|
|
return new AddSelect(...$fields); |
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
/** |
279
|
|
|
* @param string $dqlAlias |
280
|
|
|
* |
281
|
|
|
* @return SelectEntity |
282
|
|
|
*/ |
283
|
|
|
public static function selectEntity($dqlAlias) |
284
|
|
|
{ |
285
|
|
|
return new SelectEntity($dqlAlias); |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
/** |
289
|
|
|
* @param Filter|Operand|string $expression |
290
|
|
|
* @param string $alias |
291
|
|
|
* |
292
|
|
|
* @return SelectAs |
293
|
|
|
*/ |
294
|
|
|
public static function selectAs($expression, $alias) |
295
|
|
|
{ |
296
|
|
|
return new SelectAs($expression, $alias); |
297
|
|
|
} |
298
|
|
|
|
299
|
|
|
/** |
300
|
|
|
* @param Filter|Operand|string $expression |
301
|
|
|
* @param string $alias |
302
|
|
|
* |
303
|
|
|
* @return SelectHiddenAs |
304
|
|
|
*/ |
305
|
|
|
public static function selectHiddenAs($expression, $alias) |
306
|
|
|
{ |
307
|
|
|
return new SelectHiddenAs($expression, $alias); |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
// Result modifier |
311
|
|
|
|
312
|
|
|
/** |
313
|
|
|
* @return AsArray |
314
|
|
|
*/ |
315
|
|
|
public static function asArray() |
316
|
|
|
{ |
317
|
|
|
return new AsArray(); |
318
|
|
|
} |
319
|
|
|
|
320
|
|
|
/** |
321
|
|
|
* @return AsSingleScalar |
322
|
|
|
*/ |
323
|
|
|
public static function asSingleScalar() |
324
|
|
|
{ |
325
|
|
|
return new AsSingleScalar(); |
326
|
|
|
} |
327
|
|
|
|
328
|
|
|
/** |
329
|
|
|
* @return AsScalar |
330
|
|
|
*/ |
331
|
|
|
public static function asScalar() |
332
|
|
|
{ |
333
|
|
|
return new AsScalar(); |
334
|
|
|
} |
335
|
|
|
|
336
|
|
|
/** |
337
|
|
|
* @param int $cacheLifetime How many seconds the cached entry is valid |
338
|
|
|
* |
339
|
|
|
* @return Cache |
340
|
|
|
*/ |
341
|
|
|
public static function cache($cacheLifetime) |
342
|
|
|
{ |
343
|
|
|
return new Cache($cacheLifetime); |
344
|
|
|
} |
345
|
|
|
|
346
|
|
|
/** |
347
|
|
|
* @param int $roundSeconds How may seconds to round time |
348
|
|
|
* |
349
|
|
|
* @return RoundDateTime |
350
|
|
|
*/ |
351
|
|
|
public static function roundDateTimeParams($roundSeconds) |
352
|
|
|
{ |
353
|
|
|
return new RoundDateTime($roundSeconds); |
354
|
|
|
} |
355
|
|
|
|
356
|
|
|
// Filters |
357
|
|
|
|
358
|
|
|
/** |
359
|
|
|
* @param Operand|string $field |
360
|
|
|
* @param string|null $dqlAlias |
361
|
|
|
* |
362
|
|
|
* @return IsNull |
363
|
|
|
*/ |
364
|
|
|
public static function isNull($field, $dqlAlias = null) |
365
|
|
|
{ |
366
|
|
|
return new IsNull($field, $dqlAlias); |
367
|
|
|
} |
368
|
|
|
|
369
|
|
|
/** |
370
|
|
|
* @param Operand|string $field |
371
|
|
|
* @param string|null $dqlAlias |
372
|
|
|
* |
373
|
|
|
* @return IsNotNull |
374
|
|
|
*/ |
375
|
|
|
public static function isNotNull($field, $dqlAlias = null) |
376
|
|
|
{ |
377
|
|
|
return new IsNotNull($field, $dqlAlias); |
378
|
|
|
} |
379
|
|
|
|
380
|
|
|
/** |
381
|
|
|
* Make sure the $field has a value equals to $value. |
382
|
|
|
* |
383
|
|
|
* @param Operand|string $field |
384
|
|
|
* @param Operand|mixed $value |
385
|
|
|
* @param string|null $dqlAlias |
386
|
|
|
* |
387
|
|
|
* @return In |
388
|
|
|
*/ |
389
|
|
|
public static function in($field, $value, $dqlAlias = null) |
390
|
|
|
{ |
391
|
|
|
return new In($field, $value, $dqlAlias); |
392
|
|
|
} |
393
|
|
|
|
394
|
|
|
/** |
395
|
|
|
* @param Operand|string $field |
396
|
|
|
* @param Operand|mixed $value |
397
|
|
|
* @param string|null $dqlAlias |
398
|
|
|
* |
399
|
|
|
* @return Not |
400
|
|
|
*/ |
401
|
|
|
public static function notIn($field, $value, $dqlAlias = null) |
402
|
|
|
{ |
403
|
|
|
return new Not(new In($field, $value, $dqlAlias)); |
404
|
|
|
} |
405
|
|
|
|
406
|
|
|
/** |
407
|
|
|
* @param Operand|string $field |
408
|
|
|
* @param Operand|mixed $value |
409
|
|
|
* @param string|null $dqlAlias |
410
|
|
|
* |
411
|
|
|
* @return Equals |
412
|
|
|
*/ |
413
|
|
|
public static function eq($field, $value, $dqlAlias = null) |
414
|
|
|
{ |
415
|
|
|
return new Equals($field, $value, $dqlAlias); |
416
|
|
|
} |
417
|
|
|
|
418
|
|
|
/** |
419
|
|
|
* @param Operand|string $field |
420
|
|
|
* @param Operand|mixed $value |
421
|
|
|
* @param string|null $dqlAlias |
422
|
|
|
* |
423
|
|
|
* @return NotEquals |
424
|
|
|
*/ |
425
|
|
|
public static function neq($field, $value, $dqlAlias = null) |
426
|
|
|
{ |
427
|
|
|
return new NotEquals($field, $value, $dqlAlias); |
428
|
|
|
} |
429
|
|
|
|
430
|
|
|
/** |
431
|
|
|
* @param Operand|string $field |
432
|
|
|
* @param Operand|mixed $value |
433
|
|
|
* @param string|null $dqlAlias |
434
|
|
|
* |
435
|
|
|
* @return LessThan |
436
|
|
|
*/ |
437
|
|
|
public static function lt($field, $value, $dqlAlias = null) |
438
|
|
|
{ |
439
|
|
|
return new LessThan($field, $value, $dqlAlias); |
440
|
|
|
} |
441
|
|
|
|
442
|
|
|
/** |
443
|
|
|
* @param Operand|string $field |
444
|
|
|
* @param Operand|mixed $value |
445
|
|
|
* @param string|null $dqlAlias |
446
|
|
|
* |
447
|
|
|
* @return LessOrEqualThan |
448
|
|
|
*/ |
449
|
|
|
public static function lte($field, $value, $dqlAlias = null) |
450
|
|
|
{ |
451
|
|
|
return new LessOrEqualThan($field, $value, $dqlAlias); |
452
|
|
|
} |
453
|
|
|
|
454
|
|
|
/** |
455
|
|
|
* @param Operand|string $field |
456
|
|
|
* @param Operand|mixed $value |
457
|
|
|
* @param string|null $dqlAlias |
458
|
|
|
* |
459
|
|
|
* @return GreaterThan |
460
|
|
|
*/ |
461
|
|
|
public static function gt($field, $value, $dqlAlias = null) |
462
|
|
|
{ |
463
|
|
|
return new GreaterThan($field, $value, $dqlAlias); |
464
|
|
|
} |
465
|
|
|
|
466
|
|
|
/** |
467
|
|
|
* @param Operand|string $field |
468
|
|
|
* @param Operand|mixed $value |
469
|
|
|
* @param string|null $dqlAlias |
470
|
|
|
* |
471
|
|
|
* @return GreaterOrEqualThan |
472
|
|
|
*/ |
473
|
|
|
public static function gte($field, $value, $dqlAlias = null) |
474
|
|
|
{ |
475
|
|
|
return new GreaterOrEqualThan($field, $value, $dqlAlias); |
476
|
|
|
} |
477
|
|
|
|
478
|
|
|
/** |
479
|
|
|
* @param Operand|string $field |
480
|
|
|
* @param LikePattern|string $value |
481
|
|
|
* @param string $format |
482
|
|
|
* @param string|null $dqlAlias |
483
|
|
|
* |
484
|
|
|
* @return Like |
485
|
|
|
*/ |
486
|
|
|
public static function like($field, $value, $format = Like::CONTAINS, $dqlAlias = null) |
487
|
|
|
{ |
488
|
|
|
return new Like($field, $value, $format, $dqlAlias); |
489
|
|
|
} |
490
|
|
|
|
491
|
|
|
/** |
492
|
|
|
* @param string $value |
493
|
|
|
* @param string|null $dqlAlias |
494
|
|
|
* |
495
|
|
|
* @return InstanceOfX |
496
|
|
|
*/ |
497
|
|
|
public static function instanceOfX($value, $dqlAlias = null) |
498
|
|
|
{ |
499
|
|
|
return new InstanceOfX($value, $dqlAlias); |
500
|
|
|
} |
501
|
|
|
|
502
|
|
|
/** |
503
|
|
|
* @param Operand|string $value |
504
|
|
|
* @param Operand|string $field |
505
|
|
|
* @param string|null $dqlAlias |
506
|
|
|
* |
507
|
|
|
* @return MemberOfX |
508
|
|
|
*/ |
509
|
|
|
public static function memberOfX($value, $field, $dqlAlias = null) |
510
|
|
|
{ |
511
|
|
|
return new MemberOfX($value, $field, $dqlAlias); |
512
|
|
|
} |
513
|
|
|
|
514
|
|
|
// Specifications |
515
|
|
|
|
516
|
|
|
/** |
517
|
|
|
* @param Filter|QueryModifier $spec |
518
|
|
|
* |
519
|
|
|
* @return CountOf |
520
|
|
|
*/ |
521
|
|
|
public static function countOf($spec) |
522
|
|
|
{ |
523
|
|
|
return new CountOf($spec); |
524
|
|
|
} |
525
|
|
|
|
526
|
|
|
/** |
527
|
|
|
* @param Filter $spec |
528
|
|
|
* |
529
|
|
|
* @return Having |
530
|
|
|
*/ |
531
|
|
|
public static function having(Filter $spec) |
532
|
|
|
{ |
533
|
|
|
return new Having($spec); |
534
|
|
|
} |
535
|
|
|
|
536
|
|
|
// Operands |
537
|
|
|
|
538
|
|
|
/** |
539
|
|
|
* @param string $fieldName |
540
|
|
|
* @param string|null $dqlAlias |
541
|
|
|
* |
542
|
|
|
* @return Field |
543
|
|
|
*/ |
544
|
|
|
public static function field($fieldName, $dqlAlias = null) |
545
|
|
|
{ |
546
|
|
|
return new Field($fieldName, $dqlAlias); |
547
|
|
|
} |
548
|
|
|
|
549
|
|
|
/** |
550
|
|
|
* @param mixed $value |
551
|
|
|
* @param int|string|null $valueType |
552
|
|
|
* |
553
|
|
|
* @return Value |
554
|
|
|
*/ |
555
|
|
|
public static function value($value, $valueType = null) |
556
|
|
|
{ |
557
|
|
|
return new Value($value, $valueType); |
558
|
|
|
} |
559
|
|
|
|
560
|
|
|
/** |
561
|
|
|
* @param array $values |
562
|
|
|
* @param int|string|null $valueType |
563
|
|
|
* |
564
|
|
|
* @return Values |
565
|
|
|
*/ |
566
|
|
|
public static function values($values, $valueType = null) |
567
|
|
|
{ |
568
|
|
|
return new Values($values, $valueType); |
569
|
|
|
} |
570
|
|
|
|
571
|
|
|
/** |
572
|
|
|
* @param string $value |
573
|
|
|
* @param string $format |
574
|
|
|
* |
575
|
|
|
* @return LikePattern |
576
|
|
|
*/ |
577
|
|
|
public static function likePattern($value, $format = LikePattern::CONTAINS) |
578
|
|
|
{ |
579
|
|
|
return new LikePattern($value, $format); |
580
|
|
|
} |
581
|
|
|
|
582
|
|
|
/** |
583
|
|
|
* @param Operand|string $field |
584
|
|
|
* |
585
|
|
|
* @return CountDistinct |
586
|
|
|
*/ |
587
|
|
|
public static function countDistinct($field) |
588
|
|
|
{ |
589
|
|
|
return new CountDistinct($field); |
590
|
|
|
} |
591
|
|
|
|
592
|
|
|
// Arithmetic operands |
593
|
|
|
|
594
|
|
|
/** |
595
|
|
|
* @param Operand|string $field |
596
|
|
|
* @param Operand|mixed $value |
597
|
|
|
* |
598
|
|
|
* @return Addition |
599
|
|
|
*/ |
600
|
|
|
public static function add($field, $value) |
601
|
|
|
{ |
602
|
|
|
return new Addition($field, $value); |
603
|
|
|
} |
604
|
|
|
|
605
|
|
|
/** |
606
|
|
|
* @param Operand|string $field |
607
|
|
|
* @param Operand|mixed $value |
608
|
|
|
* |
609
|
|
|
* @return Subtraction |
610
|
|
|
*/ |
611
|
|
|
public static function sub($field, $value) |
612
|
|
|
{ |
613
|
|
|
return new Subtraction($field, $value); |
614
|
|
|
} |
615
|
|
|
|
616
|
|
|
/** |
617
|
|
|
* @param Operand|string $field |
618
|
|
|
* @param Operand|mixed $value |
619
|
|
|
* |
620
|
|
|
* @return Multiplication |
621
|
|
|
*/ |
622
|
|
|
public static function mul($field, $value) |
623
|
|
|
{ |
624
|
|
|
return new Multiplication($field, $value); |
625
|
|
|
} |
626
|
|
|
|
627
|
|
|
/** |
628
|
|
|
* @param Operand|string $field |
629
|
|
|
* @param Operand|mixed $value |
630
|
|
|
* |
631
|
|
|
* @return Division |
632
|
|
|
*/ |
633
|
|
|
public static function div($field, $value) |
634
|
|
|
{ |
635
|
|
|
return new Division($field, $value); |
636
|
|
|
} |
637
|
|
|
|
638
|
|
|
/** |
639
|
|
|
* @param Operand|string $field |
640
|
|
|
* @param Operand|mixed $value |
641
|
|
|
* |
642
|
|
|
* @return Modulo |
643
|
|
|
*/ |
644
|
|
|
public static function mod($field, $value) |
645
|
|
|
{ |
646
|
|
|
return new Modulo($field, $value); |
647
|
|
|
} |
648
|
|
|
|
649
|
|
|
/** |
650
|
|
|
* Call DQL function. |
651
|
|
|
* |
652
|
|
|
* Usage: |
653
|
|
|
* Spec::fun('CURRENT_DATE') |
654
|
|
|
* Spec::fun('DATE_DIFF', $date1, $date2) |
655
|
|
|
* |
656
|
|
|
* @param string $functionName |
657
|
|
|
* @param mixed ...$arguments |
658
|
|
|
* |
659
|
|
|
* @return PlatformFunction |
660
|
|
|
*/ |
661
|
|
|
public static function fun($functionName, ...$arguments) |
662
|
|
|
{ |
663
|
|
|
return new PlatformFunction($functionName, ...$arguments); |
664
|
|
|
} |
665
|
|
|
|
666
|
|
|
/** |
667
|
|
|
* @param string $alias |
668
|
|
|
* |
669
|
|
|
* @return Alias |
670
|
|
|
*/ |
671
|
|
|
public static function alias($alias) |
672
|
|
|
{ |
673
|
|
|
return new Alias($alias); |
674
|
|
|
} |
675
|
|
|
} |
676
|
|
|
|