1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Rougin\Windstorm\Eloquent; |
4
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Builder; |
6
|
|
|
use Rougin\Windstorm\WhereInterface; |
7
|
|
|
|
8
|
|
|
class Where implements WhereInterface |
9
|
|
|
{ |
10
|
|
|
protected $builder; |
11
|
|
|
|
12
|
|
|
protected $method = 'where'; |
13
|
|
|
|
14
|
|
|
protected $query; |
15
|
|
|
|
16
|
|
|
protected $key; |
17
|
|
|
|
18
|
|
|
protected $type; |
19
|
|
|
|
20
|
75 |
|
public function __construct(Query $query, Builder $builder, $key, $type = 'and') |
21
|
|
|
{ |
22
|
75 |
|
$this->query = $query; |
23
|
|
|
|
24
|
75 |
|
$this->builder = $builder; |
25
|
|
|
|
26
|
75 |
|
$this->key = $key; |
27
|
|
|
|
28
|
75 |
|
$this->type = $type; |
29
|
75 |
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Generates an equality comparison. |
33
|
|
|
* |
34
|
|
|
* @param mixed $value |
35
|
|
|
* @return \Rougin\Windstorm\QueryInterface |
36
|
|
|
*/ |
37
|
36 |
|
public function equals($value) |
38
|
|
|
{ |
39
|
36 |
|
return $this->where('=', $value); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Generates an non-equality comparison. |
44
|
|
|
* |
45
|
|
|
* @param mixed $value |
46
|
|
|
* @return \Rougin\Windstorm\QueryInterface |
47
|
|
|
*/ |
48
|
3 |
|
public function notEqualTo($value) |
49
|
|
|
{ |
50
|
3 |
|
return $this->where('!=', $value); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Generates a greater-than comparison. |
55
|
|
|
* |
56
|
|
|
* @param mixed $value |
57
|
|
|
* @return \Rougin\Windstorm\QueryInterface |
58
|
|
|
*/ |
59
|
3 |
|
public function greaterThan($value) |
60
|
|
|
{ |
61
|
3 |
|
return $this->where('>', $value); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Generates a greater-than or an equality comparison. |
66
|
|
|
* |
67
|
|
|
* @param mixed $value |
68
|
|
|
* @return \Rougin\Windstorm\QueryInterface |
69
|
|
|
*/ |
70
|
3 |
|
public function greaterThanOrEqualTo($value) |
71
|
|
|
{ |
72
|
3 |
|
return $this->where('>=', $value); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Generates an IN () query comparison. |
77
|
|
|
* |
78
|
|
|
* @param array $values |
79
|
|
|
* @return \Rougin\Windstorm\QueryInterface |
80
|
|
|
*/ |
81
|
3 |
|
public function in(array $values) |
82
|
|
|
{ |
83
|
3 |
|
$this->builder = $this->builder->whereIn($this->key, $values, $this->type); |
84
|
|
|
|
85
|
3 |
|
return $this->query->builder($this->builder); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Generates an NOT IN () query comparison. |
90
|
|
|
* |
91
|
|
|
* @param array $values |
92
|
|
|
* @return \Rougin\Windstorm\QueryInterface |
93
|
|
|
*/ |
94
|
3 |
|
public function notIn(array $values) |
95
|
|
|
{ |
96
|
3 |
|
$this->builder = $this->builder->whereNotIn($this->key, $values, $this->type); |
97
|
|
|
|
98
|
3 |
|
return $this->query->builder($this->builder); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Generates a false comparison. |
103
|
|
|
* |
104
|
|
|
* @return \Rougin\Windstorm\QueryInterface |
105
|
|
|
*/ |
106
|
3 |
|
public function isFalse() |
107
|
|
|
{ |
108
|
3 |
|
return $this->where('=', false); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Generates an IS NOT NULL query comparison. |
113
|
|
|
* |
114
|
|
|
* @return \Rougin\Windstorm\QueryInterface |
115
|
|
|
*/ |
116
|
3 |
|
public function isNotNull() |
117
|
|
|
{ |
118
|
3 |
|
$this->builder = $this->builder->whereNotNull($this->key, $this->type); |
119
|
|
|
|
120
|
3 |
|
return $this->query->builder($this->builder); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Generates an IS NULL query comparison. |
125
|
|
|
* |
126
|
|
|
* @return \Rougin\Windstorm\QueryInterface |
127
|
|
|
*/ |
128
|
3 |
|
public function isNull() |
129
|
|
|
{ |
130
|
3 |
|
$this->builder = $this->builder->whereNull($this->key, $this->type); |
131
|
|
|
|
132
|
3 |
|
return $this->query->builder($this->builder); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Generates a true comparison. |
137
|
|
|
* |
138
|
|
|
* @return \Rougin\Windstorm\QueryInterface |
139
|
|
|
*/ |
140
|
15 |
|
public function isTrue() |
141
|
|
|
{ |
142
|
15 |
|
return $this->where('=', true); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* Generates a less-than comparison. |
147
|
|
|
* |
148
|
|
|
* @param mixed $value |
149
|
|
|
* @return \Rougin\Windstorm\QueryInterface |
150
|
|
|
*/ |
151
|
3 |
|
public function lessThan($value) |
152
|
|
|
{ |
153
|
3 |
|
return $this->where('<', true); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* Generates a less-than or an equality comparison. |
158
|
|
|
* |
159
|
|
|
* @param mixed $value |
160
|
|
|
* @return \Rougin\Windstorm\QueryInterface |
161
|
|
|
*/ |
162
|
3 |
|
public function lessThanOrEqualTo($value) |
163
|
|
|
{ |
164
|
3 |
|
return $this->where('<=', true); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* Generates a LIKE query comparison. |
169
|
|
|
* |
170
|
|
|
* @param string $value |
171
|
|
|
* @return \Rougin\Windstorm\QueryInterface |
172
|
|
|
*/ |
173
|
3 |
|
public function like($value) |
174
|
|
|
{ |
175
|
3 |
|
return $this->where('like', $value); |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* Generates a NOT LIKE query comparison. |
180
|
|
|
* |
181
|
|
|
* @param string $value |
182
|
|
|
* @return \Rougin\Windstorm\QueryInterface |
183
|
|
|
*/ |
184
|
3 |
|
public function notLike($value) |
185
|
|
|
{ |
186
|
3 |
|
return $this->where('not like', $value); |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* Sets the query builder instance. |
191
|
|
|
* |
192
|
|
|
* @param string $operator |
193
|
|
|
* @param mixed $value |
194
|
|
|
* @return \Rougin\Windstorm\QueryInterface |
195
|
|
|
*/ |
196
|
63 |
|
protected function where($operator, $value) |
197
|
|
|
{ |
198
|
63 |
|
$method = (string) $this->method; |
199
|
|
|
|
200
|
63 |
|
$this->builder = $this->builder->$method($this->key, $operator, $value, $this->type); |
201
|
|
|
|
202
|
63 |
|
return $this->query->builder($this->builder); |
203
|
|
|
} |
204
|
|
|
} |
205
|
|
|
|