1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Bdf\Prime\Query\Extension; |
4
|
|
|
|
5
|
|
|
use Bdf\Prime\Query\Clause; |
6
|
|
|
use Bdf\Prime\Query\Compiler\CompilerState; |
7
|
|
|
use Bdf\Prime\Query\Contract\Whereable; |
8
|
|
|
use Doctrine\DBAL\Query\Expression\CompositeExpression; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Trait for where() method |
12
|
|
|
* |
13
|
|
|
* @see Whereable |
14
|
|
|
* @property CompilerState $compilerState |
15
|
|
|
* |
16
|
|
|
* @psalm-require-implements Whereable |
17
|
|
|
*/ |
18
|
|
|
trait SimpleWhereTrait |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* {@inheritdoc} |
22
|
|
|
* |
23
|
|
|
* @see Whereable::where() |
24
|
|
|
*/ |
25
|
655 |
|
public function where($column, $operator = null, $value = null) |
26
|
|
|
{ |
27
|
655 |
|
if (!is_string($column) && is_callable($column)) { |
28
|
1 |
|
$this->nested($column, $operator ?: CompositeExpression::TYPE_AND); |
29
|
|
|
} else { |
30
|
655 |
|
$this->compilerState->invalidate('where'); |
31
|
|
|
|
32
|
655 |
|
$this->buildClause('where', $column, $operator, $value); |
33
|
|
|
} |
34
|
|
|
|
35
|
655 |
|
return $this; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* {@inheritdoc} |
40
|
|
|
* |
41
|
|
|
* @see Whereable::whereReplace() |
42
|
|
|
*/ |
43
|
12 |
|
public function whereReplace(string $column, $operator = null, $value = null) |
44
|
|
|
{ |
45
|
12 |
|
$this->compilerState->invalidate('where'); |
46
|
12 |
|
$this->replaceClause('where', $column, $operator, $value); |
47
|
12 |
|
return $this; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* {@inheritdoc} |
52
|
|
|
* |
53
|
|
|
* @see Whereable::orWhere() |
54
|
|
|
*/ |
55
|
12 |
|
public function orWhere($column, $operator = null, $value = null) |
56
|
|
|
{ |
57
|
12 |
|
if (!is_string($column) && is_callable($column)) { |
58
|
|
|
$this->nested($column, $operator ?: CompositeExpression::TYPE_OR); |
59
|
|
|
} else { |
60
|
12 |
|
$this->compilerState->invalidate('where'); |
61
|
|
|
|
62
|
12 |
|
$this->buildClause('where', $column, $operator, $value, CompositeExpression::TYPE_OR); |
63
|
|
|
} |
64
|
|
|
|
65
|
12 |
|
return $this; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* {@inheritdoc} |
70
|
|
|
* |
71
|
|
|
* @see Whereable::whereNull() |
72
|
|
|
*/ |
73
|
2 |
|
public function whereNull(string $column, string $type = CompositeExpression::TYPE_AND) |
74
|
|
|
{ |
75
|
2 |
|
$this->compilerState->invalidate('where'); |
76
|
|
|
|
77
|
2 |
|
return $this->buildClause('where', $column, '=', null, $type); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* {@inheritdoc} |
82
|
|
|
* |
83
|
|
|
* @see Whereable::whereNotNull() |
84
|
|
|
*/ |
85
|
2 |
|
public function whereNotNull(string $column, string $type = CompositeExpression::TYPE_AND) |
86
|
|
|
{ |
87
|
2 |
|
$this->compilerState->invalidate('where'); |
88
|
|
|
|
89
|
2 |
|
return $this->buildClause('where', $column, '!=', null, $type); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* {@inheritdoc} |
94
|
|
|
* |
95
|
|
|
* @see Whereable::orWhereNull() |
96
|
|
|
*/ |
97
|
1 |
|
public function orWhereNull(string $column) |
98
|
|
|
{ |
99
|
1 |
|
return $this->whereNull($column, CompositeExpression::TYPE_OR); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* {@inheritdoc} |
104
|
|
|
* |
105
|
|
|
* @see Whereable::orWhereNotNull() |
106
|
|
|
*/ |
107
|
1 |
|
public function orWhereNotNull(string $column) |
108
|
|
|
{ |
109
|
1 |
|
return $this->whereNotNull($column, CompositeExpression::TYPE_OR); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* {@inheritdoc} |
114
|
|
|
* |
115
|
|
|
* @see Whereable::whereRaw() |
116
|
|
|
*/ |
117
|
7 |
|
public function whereRaw($raw, string $type = CompositeExpression::TYPE_AND) |
118
|
|
|
{ |
119
|
7 |
|
$this->compilerState->invalidate('where'); |
120
|
|
|
|
121
|
7 |
|
return $this->buildRaw('where', $raw, $type); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* {@inheritdoc} |
126
|
|
|
* |
127
|
|
|
* @see Whereable::orWhereRaw() |
128
|
|
|
*/ |
129
|
2 |
|
public function orWhereRaw($raw) |
130
|
|
|
{ |
131
|
2 |
|
return $this->whereRaw($raw, CompositeExpression::TYPE_OR); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* {@inheritdoc} |
136
|
|
|
* |
137
|
|
|
* @see Whereable::nested() |
138
|
|
|
*/ |
139
|
2 |
|
public function nested(callable $callback, string $type = CompositeExpression::TYPE_AND) |
140
|
|
|
{ |
141
|
2 |
|
$this->compilerState->invalidate('where'); |
142
|
|
|
|
143
|
2 |
|
return $this->buildNested('where', $callback, $type); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* {@inheritdoc} |
148
|
|
|
* |
149
|
|
|
* @see Clause::buildClause() |
150
|
|
|
*/ |
151
|
|
|
abstract public function buildClause(string $statement, $expression, $operator = null, $value = null, string $type = CompositeExpression::TYPE_AND); |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* {@inheritdoc} |
155
|
|
|
* |
156
|
|
|
* @see Clause::replaceClause() |
157
|
|
|
*/ |
158
|
|
|
abstract public function replaceClause(string $statement, string $expression, $operator = null, $value = null); |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* {@inheritdoc} |
162
|
|
|
* |
163
|
|
|
* @see Clause::buildNested() |
164
|
|
|
*/ |
165
|
|
|
abstract public function buildNested(string $statement, callable $callback, string $type = CompositeExpression::TYPE_AND); |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* {@inheritdoc} |
169
|
|
|
* |
170
|
|
|
* @see Clause::buildRaw() |
171
|
|
|
*/ |
172
|
|
|
abstract public function buildRaw(string $statement, $expression, string $type = CompositeExpression::TYPE_AND); |
173
|
|
|
} |
174
|
|
|
|