/
Operators.php
129 lines (104 loc) · 2.9 KB
/
Operators.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
declare(strict_types = 1);
namespace hanneskod\yaysondb;
use hanneskod\yaysondb\Expression\ExpressionInterface;
/**
* Collection of query operators
*/
class Operators
{
public static function doc(array $query)
{
return new Expression\Doc($query);
}
public static function not(ExpressionInterface $expr)
{
return new Expression\Not($expr);
}
public static function exists()
{
return new Expression\Exists();
}
public static function type($type)
{
return new Expression\Type($type);
}
public static function in(array $list)
{
return new Expression\In($list);
}
public static function regexp($regexp)
{
return new Expression\Regexp($regexp);
}
public static function equals($operand)
{
return new Expression\Comparator\Equals($operand);
}
public static function same($operand)
{
return new Expression\Comparator\Same($operand);
}
public static function greaterThan($operand)
{
return new Expression\Comparator\GreaterThan($operand);
}
public static function greaterThanOrEquals($operand)
{
return self::atLeastOne(
self::equals($operand),
self::greaterThan($operand)
);
}
public static function lessThan($operand)
{
return self::not(self::greaterThanOrEquals($operand));
}
public static function lessThanOrEquals($operand)
{
return self::atLeastOne(
self::equals($operand),
self::lessThan($operand)
);
}
public static function all(ExpressionInterface ...$exprs)
{
return new Expression\Counter\All(...$exprs);
}
public static function atLeastOne(ExpressionInterface ...$exprs)
{
return new Expression\Counter\AtLeastOne(...$exprs);
}
public static function exactly($count, ExpressionInterface ...$exprs)
{
return new Expression\Counter\Exactly($count, ...$exprs);
}
public static function none(ExpressionInterface ...$exprs)
{
return self::not(self::atLeastOne(...$exprs));
}
public static function one(ExpressionInterface ...$exprs)
{
return self::exactly(1, ...$exprs);
}
public static function listAll(ExpressionInterface $expr)
{
return new Expression\Set\ListAll($expr);
}
public static function listAtLeastOne(ExpressionInterface $expr)
{
return new Expression\Set\ListAtLeastOne($expr);
}
public static function listExactly($count, ExpressionInterface $expr)
{
return new Expression\Set\ListExactly($count, $expr);
}
public static function listNone(ExpressionInterface $expr)
{
return self::not(self::listAtLeastOne($expr));
}
public static function listOne(ExpressionInterface $expr)
{
return self::listExactly(1, $expr);
}
}