1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace TBolier\RethinkQL\Query; |
5
|
|
|
|
6
|
|
|
use TBolier\RethinkQL\Message\MessageInterface; |
7
|
|
|
use TBolier\RethinkQL\Query\Exception\QueryException; |
8
|
|
|
use TBolier\RethinkQL\Query\Logic\AndLogic; |
9
|
|
|
use TBolier\RethinkQL\Query\Logic\EqualLogic; |
10
|
|
|
use TBolier\RethinkQL\Query\Logic\FuncLogic; |
11
|
|
|
use TBolier\RethinkQL\Query\Logic\GetFieldLogic; |
12
|
|
|
use TBolier\RethinkQL\Query\Logic\GreaterThanLogic; |
13
|
|
|
use TBolier\RethinkQL\Query\Logic\LowerThanLogic; |
14
|
|
|
use TBolier\RethinkQL\Query\Logic\NotEqualLogic; |
15
|
|
|
use TBolier\RethinkQL\Query\Logic\OrLogic; |
16
|
|
|
use TBolier\RethinkQL\RethinkInterface; |
17
|
|
|
|
18
|
|
|
class Row extends AbstractQuery implements RowInterface |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var QueryInterface |
22
|
|
|
*/ |
23
|
|
|
private $function; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var QueryInterface |
27
|
|
|
*/ |
28
|
|
|
private $query; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
private $value; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param RethinkInterface $rethink |
37
|
|
|
* @param MessageInterface $message |
38
|
|
|
* @param string $value |
39
|
|
|
*/ |
40
|
|
|
public function __construct( |
41
|
|
|
RethinkInterface $rethink, |
42
|
|
|
MessageInterface $message, |
43
|
|
|
string $value |
44
|
|
|
) { |
45
|
|
|
$this->value = $value; |
46
|
|
|
$this->rethink = $rethink; |
47
|
|
|
$this->message = $message; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @inheritdoc |
52
|
|
|
* @throws QueryException |
53
|
|
|
*/ |
54
|
|
|
public function eq($value): RowInterface |
55
|
|
|
{ |
56
|
|
|
if (!\is_scalar($value)) { |
57
|
|
|
throw new QueryException('Only scalar types are supported for lower than manipulations.'); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
$this->function = new EqualLogic( |
61
|
|
|
$this->rethink, |
62
|
|
|
$this->message, |
63
|
|
|
new GetFieldLogic($this->rethink, $this->message, $this->value), |
64
|
|
|
$value |
65
|
|
|
); |
66
|
|
|
|
67
|
|
|
$this->query = new FuncLogic( |
68
|
|
|
$this->rethink, |
69
|
|
|
$this->message, |
70
|
|
|
$this->function |
71
|
|
|
); |
72
|
|
|
|
73
|
|
|
return $this; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @inheritdoc |
78
|
|
|
* @throws QueryException |
79
|
|
|
*/ |
80
|
|
|
public function ne($value): RowInterface |
81
|
|
|
{ |
82
|
|
|
if (!\is_scalar($value)) { |
83
|
|
|
throw new QueryException('Only scalar types are supported for lower than manipulations.'); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
$this->function = new NotEqualLogic( |
87
|
|
|
$this->rethink, |
88
|
|
|
$this->message, |
89
|
|
|
new GetFieldLogic($this->rethink, $this->message, $this->value), |
90
|
|
|
$value |
91
|
|
|
); |
92
|
|
|
|
93
|
|
|
$this->query = new FuncLogic( |
94
|
|
|
$this->rethink, |
95
|
|
|
$this->message, |
96
|
|
|
$this->function |
97
|
|
|
); |
98
|
|
|
|
99
|
|
|
return $this; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @inheritdoc |
104
|
|
|
* @throws QueryException |
105
|
|
|
*/ |
106
|
|
|
public function lt($value): RowInterface |
107
|
|
|
{ |
108
|
|
|
if (!\is_scalar($value)) { |
109
|
|
|
throw new QueryException('Only scalar types are supported for lower than manipulations.'); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
$this->function = new LowerThanLogic( |
113
|
|
|
$this->rethink, |
114
|
|
|
$this->message, |
115
|
|
|
new GetFieldLogic($this->rethink, $this->message, $this->value), |
116
|
|
|
$value |
117
|
|
|
); |
118
|
|
|
|
119
|
|
|
$this->query = new FuncLogic( |
120
|
|
|
$this->rethink, |
121
|
|
|
$this->message, |
122
|
|
|
$this->function |
123
|
|
|
); |
124
|
|
|
|
125
|
|
|
return $this; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @inheritdoc |
130
|
|
|
* @throws QueryException |
131
|
|
|
*/ |
132
|
|
|
public function gt($value): RowInterface |
133
|
|
|
{ |
134
|
|
|
if (!\is_scalar($value)) { |
135
|
|
|
throw new QueryException('Only scalar types are supported for greater than manipulations.'); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
$this->function = new GreaterThanLogic( |
139
|
|
|
$this->rethink, |
140
|
|
|
$this->message, |
141
|
|
|
new GetFieldLogic($this->rethink, $this->message, $this->value), |
142
|
|
|
$value |
143
|
|
|
); |
144
|
|
|
|
145
|
|
|
$this->query = new FuncLogic( |
146
|
|
|
$this->rethink, |
147
|
|
|
$this->message, |
148
|
|
|
$this->function |
149
|
|
|
); |
150
|
|
|
|
151
|
|
|
return $this; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* @param RowInterface $row |
156
|
|
|
* @return RowInterface |
157
|
|
|
*/ |
158
|
|
|
public function and(RowInterface $row): RowInterface |
159
|
|
|
{ |
160
|
|
|
$this->function = new AndLogic( |
161
|
|
|
$this->rethink, |
162
|
|
|
$this->message, |
163
|
|
|
$this->function, |
164
|
|
|
$row->getFunction() |
165
|
|
|
); |
166
|
|
|
|
167
|
|
|
$this->query = new FuncLogic( |
168
|
|
|
$this->rethink, |
169
|
|
|
$this->message, |
170
|
|
|
$this->function |
171
|
|
|
); |
172
|
|
|
|
173
|
|
|
return $this; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* @param RowInterface $row |
178
|
|
|
* @return RowInterface |
179
|
|
|
*/ |
180
|
|
|
public function or(RowInterface $row): RowInterface |
181
|
|
|
{ |
182
|
|
|
$this->function = new OrLogic( |
183
|
|
|
$this->rethink, |
184
|
|
|
$this->message, |
185
|
|
|
$this->function, |
186
|
|
|
$row->getFunction() |
187
|
|
|
); |
188
|
|
|
|
189
|
|
|
$this->query = new FuncLogic( |
190
|
|
|
$this->rethink, |
191
|
|
|
$this->message, |
192
|
|
|
$this->function |
193
|
|
|
); |
194
|
|
|
|
195
|
|
|
return $this; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* @inheritdoc |
200
|
|
|
*/ |
201
|
|
|
public function toArray(): array |
202
|
|
|
{ |
203
|
|
|
return $this->query->toArray(); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* @return QueryInterface |
208
|
|
|
*/ |
209
|
|
|
public function getFunction(): QueryInterface |
210
|
|
|
{ |
211
|
|
|
return $this->function; |
212
|
|
|
} |
213
|
|
|
} |
214
|
|
|
|