|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the Tarantool Client package. |
|
7
|
|
|
* |
|
8
|
|
|
* (c) Eugene Leonovich <[email protected]> |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
11
|
|
|
* file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Tarantool\Client\Schema; |
|
15
|
|
|
|
|
16
|
|
|
final class Operations |
|
17
|
|
|
{ |
|
18
|
|
|
private $operations; |
|
19
|
|
|
|
|
20
|
10 |
|
private function __construct(array $operation) |
|
21
|
|
|
{ |
|
22
|
10 |
|
$this->operations = [$operation]; |
|
23
|
10 |
|
} |
|
24
|
|
|
|
|
25
|
|
|
public static function add(int $fieldNumber, int $value) : self |
|
26
|
|
|
{ |
|
27
|
|
|
return new self(['+', $fieldNumber, $value]); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function andAdd(int $fieldNumber, int $value) : self |
|
31
|
|
|
{ |
|
32
|
|
|
$new = clone $this; |
|
33
|
|
|
$new->operations[] = ['+', $fieldNumber, $value]; |
|
34
|
|
|
|
|
35
|
|
|
return $new; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public static function subtract(int $fieldNumber, int $value) : self |
|
39
|
|
|
{ |
|
40
|
|
|
return new self(['-', $fieldNumber, $value]); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function andSubtract(int $fieldNumber, int $value) : self |
|
44
|
|
|
{ |
|
45
|
|
|
$new = clone $this; |
|
46
|
|
|
$new->operations[] = ['-', $fieldNumber, $value]; |
|
47
|
|
|
|
|
48
|
|
|
return $new; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public static function bitAnd(int $fieldNumber, int $value) : self |
|
52
|
|
|
{ |
|
53
|
|
|
return new self(['&', $fieldNumber, $value]); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function andBitAnd(int $fieldNumber, int $value) : self |
|
57
|
|
|
{ |
|
58
|
|
|
$new = clone $this; |
|
59
|
|
|
$new->operations[] = ['&', $fieldNumber, $value]; |
|
60
|
|
|
|
|
61
|
|
|
return $new; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public static function bitOr(int $fieldNumber, int $value) : self |
|
65
|
|
|
{ |
|
66
|
|
|
return new self(['|', $fieldNumber, $value]); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function andBitOr(int $fieldNumber, int $value) : self |
|
70
|
|
|
{ |
|
71
|
|
|
$new = clone $this; |
|
72
|
|
|
$new->operations[] = ['|', $fieldNumber, $value]; |
|
73
|
|
|
|
|
74
|
|
|
return $new; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public static function bitXor(int $fieldNumber, int $value) : self |
|
78
|
|
|
{ |
|
79
|
|
|
return new self(['^', $fieldNumber, $value]); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function andBitXor(int $fieldNumber, int $value) : self |
|
83
|
|
|
{ |
|
84
|
|
|
$new = clone $this; |
|
85
|
|
|
$new->operations[] = ['^', $fieldNumber, $value]; |
|
86
|
|
|
|
|
87
|
|
|
return $new; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
6 |
|
public static function splice(int $fieldNumber, int $offset, int $length, string $replacement) : self |
|
91
|
|
|
{ |
|
92
|
6 |
|
return new self([':', $fieldNumber, $offset, $length, $replacement]); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
public function andSplice(int $fieldNumber, int $offset, int $length, string $replacement) : self |
|
96
|
|
|
{ |
|
97
|
|
|
$new = clone $this; |
|
98
|
|
|
$new->operations[] = [':', $fieldNumber, $offset, $length, $replacement]; |
|
99
|
|
|
|
|
100
|
|
|
return $new; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
public static function insert(int $fieldNumber, int $value) : self |
|
104
|
|
|
{ |
|
105
|
|
|
return new self(['!', $fieldNumber, $value]); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
public function andInsert(int $fieldNumber, int $value) : self |
|
109
|
|
|
{ |
|
110
|
|
|
$new = clone $this; |
|
111
|
|
|
$new->operations[] = ['!', $fieldNumber, $value]; |
|
112
|
|
|
|
|
113
|
|
|
return $new; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
public static function delete(int $fieldNumber, int $value) : self |
|
117
|
|
|
{ |
|
118
|
|
|
return new self(['#', $fieldNumber, $value]); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
public function andDelete(int $fieldNumber, int $value) : self |
|
122
|
|
|
{ |
|
123
|
|
|
$new = clone $this; |
|
124
|
|
|
$new->operations[] = ['#', $fieldNumber, $value]; |
|
125
|
|
|
|
|
126
|
|
|
return $new; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
4 |
|
public static function set(int $fieldNumber, $value) : self |
|
130
|
|
|
{ |
|
131
|
4 |
|
return new self(['=', $fieldNumber, $value]); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
public function andSet(int $fieldNumber, $value) : self |
|
135
|
|
|
{ |
|
136
|
|
|
$new = clone $this; |
|
137
|
|
|
$new->operations[] = ['=', $fieldNumber, $value]; |
|
138
|
|
|
|
|
139
|
|
|
return $new; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
18 |
|
public function toArray() : array |
|
143
|
|
|
{ |
|
144
|
18 |
|
return $this->operations; |
|
145
|
|
|
} |
|
146
|
|
|
} |
|
147
|
|
|
|