1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the tarantool/client package. |
5
|
|
|
* |
6
|
|
|
* (c) Eugene Leonovich <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace Tarantool\Client\Schema; |
15
|
|
|
|
16
|
|
|
final class Criteria |
17
|
|
|
{ |
18
|
|
|
/** @var int|string */ |
19
|
|
|
private $index = 0; |
20
|
|
|
|
21
|
|
|
/** @var array<int, mixed> */ |
22
|
|
|
private $key = []; |
23
|
|
|
|
24
|
|
|
/** @var int */ |
25
|
|
|
private $limit = \PHP_INT_MAX & 0xffffffff; |
26
|
|
|
|
27
|
|
|
/** @var int */ |
28
|
|
|
private $offset = 0; |
29
|
|
|
|
30
|
|
|
/** @psalm-var null|IteratorTypes::* */ |
31
|
|
|
private $iteratorType; |
32
|
|
|
|
33
|
423 |
|
private function __construct() |
34
|
|
|
{ |
35
|
423 |
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param int|string $index |
39
|
|
|
*/ |
40
|
28 |
|
public static function index($index) : self |
41
|
|
|
{ |
42
|
28 |
|
$self = new self(); |
43
|
28 |
|
$self->index = $index; |
44
|
|
|
|
45
|
28 |
|
return $self; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param int|string $index |
50
|
|
|
*/ |
51
|
275 |
|
public function andIndex($index) : self |
52
|
|
|
{ |
53
|
275 |
|
$new = clone $this; |
54
|
275 |
|
$new->index = $index; |
55
|
|
|
|
56
|
275 |
|
return $new; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @return int|string |
61
|
|
|
*/ |
62
|
291 |
|
public function getIndex() |
63
|
|
|
{ |
64
|
291 |
|
return $this->index; |
65
|
|
|
} |
66
|
|
|
|
67
|
287 |
|
public static function key(array $key) : self |
68
|
|
|
{ |
69
|
287 |
|
$self = new self(); |
70
|
287 |
|
$self->key = $key; |
71
|
|
|
|
72
|
287 |
|
return $self; |
73
|
|
|
} |
74
|
|
|
|
75
|
8 |
|
public function andKey(array $key) : self |
76
|
|
|
{ |
77
|
8 |
|
$new = clone $this; |
78
|
8 |
|
$new->key = $key; |
79
|
|
|
|
80
|
8 |
|
return $new; |
81
|
|
|
} |
82
|
|
|
|
83
|
287 |
|
public function getKey() : array |
84
|
|
|
{ |
85
|
287 |
|
return $this->key; |
86
|
|
|
} |
87
|
|
|
|
88
|
8 |
|
public static function limit(int $limit) : self |
89
|
|
|
{ |
90
|
8 |
|
$self = new self(); |
91
|
8 |
|
$self->limit = $limit; |
92
|
|
|
|
93
|
8 |
|
return $self; |
94
|
|
|
} |
95
|
|
|
|
96
|
4 |
|
public function andLimit(int $limit) : self |
97
|
|
|
{ |
98
|
4 |
|
$new = clone $this; |
99
|
4 |
|
$new->limit = $limit; |
100
|
|
|
|
101
|
4 |
|
return $new; |
102
|
|
|
} |
103
|
|
|
|
104
|
283 |
|
public function getLimit() : int |
105
|
|
|
{ |
106
|
283 |
|
return $this->limit; |
107
|
|
|
} |
108
|
|
|
|
109
|
8 |
|
public static function offset(int $offset) : self |
110
|
|
|
{ |
111
|
8 |
|
$self = new self(); |
112
|
8 |
|
$self->offset = $offset; |
113
|
|
|
|
114
|
8 |
|
return $self; |
115
|
|
|
} |
116
|
|
|
|
117
|
4 |
|
public function andOffset(int $offset) : self |
118
|
|
|
{ |
119
|
4 |
|
$new = clone $this; |
120
|
4 |
|
$new->offset = $offset; |
121
|
|
|
|
122
|
4 |
|
return $new; |
123
|
|
|
} |
124
|
|
|
|
125
|
283 |
|
public function getOffset() : int |
126
|
|
|
{ |
127
|
283 |
|
return $this->offset; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @psalm-param IteratorTypes::* $iteratorType |
132
|
|
|
*/ |
133
|
104 |
|
public static function iterator(int $iteratorType) : self |
134
|
|
|
{ |
135
|
104 |
|
$self = new self(); |
136
|
104 |
|
$self->iteratorType = $iteratorType; |
137
|
|
|
|
138
|
104 |
|
return $self; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @psalm-param IteratorTypes::* $iteratorType |
143
|
|
|
*/ |
144
|
52 |
|
public function andIterator(int $iteratorType) : self |
145
|
|
|
{ |
146
|
52 |
|
$new = clone $this; |
147
|
52 |
|
$new->iteratorType = $iteratorType; |
148
|
|
|
|
149
|
52 |
|
return $new; |
150
|
|
|
} |
151
|
|
|
|
152
|
48 |
|
public static function eqIterator() : self |
153
|
|
|
{ |
154
|
48 |
|
return self::iterator(IteratorTypes::EQ); |
155
|
|
|
} |
156
|
|
|
|
157
|
4 |
|
public function andEqIterator() : self |
158
|
|
|
{ |
159
|
4 |
|
return $this->andIterator(IteratorTypes::EQ); |
160
|
|
|
} |
161
|
|
|
|
162
|
4 |
|
public static function reqIterator() : self |
163
|
|
|
{ |
164
|
4 |
|
return self::iterator(IteratorTypes::REQ); |
165
|
|
|
} |
166
|
|
|
|
167
|
4 |
|
public function andReqIterator() : self |
168
|
|
|
{ |
169
|
4 |
|
return $this->andIterator(IteratorTypes::REQ); |
170
|
|
|
} |
171
|
|
|
|
172
|
8 |
|
public static function allIterator() : self |
173
|
|
|
{ |
174
|
8 |
|
return self::iterator(IteratorTypes::ALL); |
175
|
|
|
} |
176
|
|
|
|
177
|
4 |
|
public function andAllIterator() : self |
178
|
|
|
{ |
179
|
4 |
|
return $this->andIterator(IteratorTypes::ALL); |
180
|
|
|
} |
181
|
|
|
|
182
|
4 |
|
public static function ltIterator() : self |
183
|
|
|
{ |
184
|
4 |
|
return self::iterator(IteratorTypes::LT); |
185
|
|
|
} |
186
|
|
|
|
187
|
4 |
|
public function andLtIterator() : self |
188
|
|
|
{ |
189
|
4 |
|
return $this->andIterator(IteratorTypes::LT); |
190
|
|
|
} |
191
|
|
|
|
192
|
4 |
|
public static function leIterator() : self |
193
|
|
|
{ |
194
|
4 |
|
return self::iterator(IteratorTypes::LE); |
195
|
|
|
} |
196
|
|
|
|
197
|
4 |
|
public function andLeIterator() : self |
198
|
|
|
{ |
199
|
4 |
|
return $this->andIterator(IteratorTypes::LE); |
200
|
|
|
} |
201
|
|
|
|
202
|
4 |
|
public static function geIterator() : self |
203
|
|
|
{ |
204
|
4 |
|
return self::iterator(IteratorTypes::GE); |
205
|
|
|
} |
206
|
|
|
|
207
|
4 |
|
public function andGeIterator() : self |
208
|
|
|
{ |
209
|
4 |
|
return $this->andIterator(IteratorTypes::GE); |
210
|
|
|
} |
211
|
|
|
|
212
|
4 |
|
public static function gtIterator() : self |
213
|
|
|
{ |
214
|
4 |
|
return self::iterator(IteratorTypes::GT); |
215
|
|
|
} |
216
|
|
|
|
217
|
4 |
|
public function andGtIterator() : self |
218
|
|
|
{ |
219
|
4 |
|
return $this->andIterator(IteratorTypes::GT); |
220
|
|
|
} |
221
|
|
|
|
222
|
4 |
|
public static function bitsAllSetIterator() : self |
223
|
|
|
{ |
224
|
4 |
|
return self::iterator(IteratorTypes::BITS_ALL_SET); |
225
|
|
|
} |
226
|
|
|
|
227
|
4 |
|
public function andBitsAllSetIterator() : self |
228
|
|
|
{ |
229
|
4 |
|
return $this->andIterator(IteratorTypes::BITS_ALL_SET); |
230
|
|
|
} |
231
|
|
|
|
232
|
4 |
|
public static function bitsAnySetIterator() : self |
233
|
|
|
{ |
234
|
4 |
|
return self::iterator(IteratorTypes::BITS_ANY_SET); |
235
|
|
|
} |
236
|
|
|
|
237
|
4 |
|
public function andBitsAnySetIterator() : self |
238
|
|
|
{ |
239
|
4 |
|
return $this->andIterator(IteratorTypes::BITS_ANY_SET); |
240
|
|
|
} |
241
|
|
|
|
242
|
4 |
|
public static function bitsAllNotSetIterator() : self |
243
|
|
|
{ |
244
|
4 |
|
return self::iterator(IteratorTypes::BITS_ALL_NOT_SET); |
245
|
|
|
} |
246
|
|
|
|
247
|
4 |
|
public function andBitsAllNotSetIterator() : self |
248
|
|
|
{ |
249
|
4 |
|
return $this->andIterator(IteratorTypes::BITS_ALL_NOT_SET); |
250
|
|
|
} |
251
|
|
|
|
252
|
4 |
|
public static function overlapsIterator() : self |
253
|
|
|
{ |
254
|
4 |
|
return self::iterator(IteratorTypes::OVERLAPS); |
255
|
|
|
} |
256
|
|
|
|
257
|
4 |
|
public function andOverlapsIterator() : self |
258
|
|
|
{ |
259
|
4 |
|
return $this->andIterator(IteratorTypes::OVERLAPS); |
260
|
|
|
} |
261
|
|
|
|
262
|
4 |
|
public static function neighborIterator() : self |
263
|
|
|
{ |
264
|
4 |
|
return self::iterator(IteratorTypes::NEIGHBOR); |
265
|
|
|
} |
266
|
|
|
|
267
|
4 |
|
public function andNeighborIterator() : self |
268
|
|
|
{ |
269
|
4 |
|
return $this->andIterator(IteratorTypes::NEIGHBOR); |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
/** |
273
|
|
|
* @psalm-return IteratorTypes::* |
274
|
|
|
*/ |
275
|
383 |
|
public function getIterator() : int |
276
|
|
|
{ |
277
|
383 |
|
if (null !== $this->iteratorType) { |
278
|
108 |
|
return $this->iteratorType; |
279
|
|
|
} |
280
|
|
|
|
281
|
279 |
|
return $this->key ? IteratorTypes::EQ : IteratorTypes::ALL; |
282
|
|
|
} |
283
|
|
|
} |
284
|
|
|
|