|
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 Operations |
|
17
|
|
|
{ |
|
18
|
|
|
private $operations; |
|
19
|
|
|
|
|
20
|
28 |
|
private function __construct(array $operation) |
|
21
|
|
|
{ |
|
22
|
28 |
|
$this->operations = [$operation]; |
|
23
|
28 |
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @param int|string $field |
|
27
|
|
|
*/ |
|
28
|
2 |
|
public static function add($field, int $value) : self |
|
29
|
|
|
{ |
|
30
|
2 |
|
return new self(['+', $field, $value]); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @param int|string $field |
|
35
|
|
|
*/ |
|
36
|
2 |
|
public function andAdd($field, int $value) : self |
|
37
|
|
|
{ |
|
38
|
2 |
|
$new = clone $this; |
|
39
|
2 |
|
$new->operations[] = ['+', $field, $value]; |
|
40
|
|
|
|
|
41
|
2 |
|
return $new; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @param int|string $field |
|
46
|
|
|
*/ |
|
47
|
2 |
|
public static function subtract($field, int $value) : self |
|
48
|
|
|
{ |
|
49
|
2 |
|
return new self(['-', $field, $value]); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @param int|string $field |
|
54
|
|
|
*/ |
|
55
|
2 |
|
public function andSubtract($field, int $value) : self |
|
56
|
|
|
{ |
|
57
|
2 |
|
$new = clone $this; |
|
58
|
2 |
|
$new->operations[] = ['-', $field, $value]; |
|
59
|
|
|
|
|
60
|
2 |
|
return $new; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @param int|string $field |
|
65
|
|
|
*/ |
|
66
|
2 |
|
public static function bitAnd($field, int $value) : self |
|
67
|
|
|
{ |
|
68
|
2 |
|
return new self(['&', $field, $value]); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @param int|string $field |
|
73
|
|
|
*/ |
|
74
|
2 |
|
public function andBitAnd($field, int $value) : self |
|
75
|
|
|
{ |
|
76
|
2 |
|
$new = clone $this; |
|
77
|
2 |
|
$new->operations[] = ['&', $field, $value]; |
|
78
|
|
|
|
|
79
|
2 |
|
return $new; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @param int|string $field |
|
84
|
|
|
*/ |
|
85
|
2 |
|
public static function bitOr($field, int $value) : self |
|
86
|
|
|
{ |
|
87
|
2 |
|
return new self(['|', $field, $value]); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @param int|string $field |
|
92
|
|
|
*/ |
|
93
|
2 |
|
public function andBitOr($field, int $value) : self |
|
94
|
|
|
{ |
|
95
|
2 |
|
$new = clone $this; |
|
96
|
2 |
|
$new->operations[] = ['|', $field, $value]; |
|
97
|
|
|
|
|
98
|
2 |
|
return $new; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* @param int|string $field |
|
103
|
|
|
*/ |
|
104
|
2 |
|
public static function bitXor($field, int $value) : self |
|
105
|
|
|
{ |
|
106
|
2 |
|
return new self(['^', $field, $value]); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* @param int|string $field |
|
111
|
|
|
*/ |
|
112
|
2 |
|
public function andBitXor($field, int $value) : self |
|
113
|
|
|
{ |
|
114
|
2 |
|
$new = clone $this; |
|
115
|
2 |
|
$new->operations[] = ['^', $field, $value]; |
|
116
|
|
|
|
|
117
|
2 |
|
return $new; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* @param int|string $field |
|
122
|
|
|
*/ |
|
123
|
8 |
|
public static function splice($field, int $offset, int $length, string $replacement) : self |
|
124
|
|
|
{ |
|
125
|
8 |
|
return new self([':', $field, $offset, $length, $replacement]); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* @param int|string $field |
|
130
|
|
|
*/ |
|
131
|
2 |
|
public function andSplice($field, int $offset, int $length, string $replacement) : self |
|
132
|
|
|
{ |
|
133
|
2 |
|
$new = clone $this; |
|
134
|
2 |
|
$new->operations[] = [':', $field, $offset, $length, $replacement]; |
|
135
|
|
|
|
|
136
|
2 |
|
return $new; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* @param int|string $field |
|
141
|
|
|
*/ |
|
142
|
2 |
|
public static function insert($field, int $value) : self |
|
143
|
|
|
{ |
|
144
|
2 |
|
return new self(['!', $field, $value]); |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* @param int|string $field |
|
149
|
|
|
*/ |
|
150
|
2 |
|
public function andInsert($field, int $value) : self |
|
151
|
|
|
{ |
|
152
|
2 |
|
$new = clone $this; |
|
153
|
2 |
|
$new->operations[] = ['!', $field, $value]; |
|
154
|
|
|
|
|
155
|
2 |
|
return $new; |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
/** |
|
159
|
|
|
* @param int|string $field |
|
160
|
|
|
*/ |
|
161
|
2 |
|
public static function delete($field, int $value) : self |
|
162
|
|
|
{ |
|
163
|
2 |
|
return new self(['#', $field, $value]); |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
/** |
|
167
|
|
|
* @param int|string $field |
|
168
|
|
|
*/ |
|
169
|
2 |
|
public function andDelete($field, int $value) : self |
|
170
|
|
|
{ |
|
171
|
2 |
|
$new = clone $this; |
|
172
|
2 |
|
$new->operations[] = ['#', $field, $value]; |
|
173
|
|
|
|
|
174
|
2 |
|
return $new; |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
/** |
|
178
|
|
|
* @param int|string $field |
|
179
|
|
|
*/ |
|
180
|
6 |
|
public static function set($field, $value) : self |
|
181
|
|
|
{ |
|
182
|
6 |
|
return new self(['=', $field, $value]); |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
/** |
|
186
|
|
|
* @param int|string $field |
|
187
|
|
|
*/ |
|
188
|
2 |
|
public function andSet($field, $value) : self |
|
189
|
|
|
{ |
|
190
|
2 |
|
$new = clone $this; |
|
191
|
2 |
|
$new->operations[] = ['=', $field, $value]; |
|
192
|
|
|
|
|
193
|
2 |
|
return $new; |
|
194
|
|
|
} |
|
195
|
|
|
|
|
196
|
34 |
|
public function toArray() : array |
|
197
|
|
|
{ |
|
198
|
34 |
|
return $this->operations; |
|
199
|
|
|
} |
|
200
|
|
|
} |
|
201
|
|
|
|