1 | <?php |
||
26 | class ExprBuilder implements ExpressionInterface |
||
27 | { |
||
28 | use ExprBuilder\ArithmeticTrait; |
||
29 | use ExprBuilder\ComparisionTrait; |
||
30 | use ExprBuilder\DateTimeTrait; |
||
31 | |||
32 | /** |
||
33 | * @var ExpressionInterface $wrappedExpression |
||
34 | */ |
||
35 | private $wrappedExpression; |
||
36 | |||
37 | /** |
||
38 | * ExprBuilder constructor. |
||
39 | */ |
||
40 | 29 | public function __construct() |
|
41 | { |
||
42 | 29 | $this->wrappedExpression = ExprNormalizer::normalizeExpression(func_get_args()); |
|
43 | 29 | } |
|
44 | |||
45 | /** |
||
46 | * @inheritdoc |
||
47 | */ |
||
48 | 2 | public function getWrappedExpression() |
|
49 | { |
||
50 | 2 | return $this->wrappedExpression; |
|
51 | } |
||
52 | |||
53 | /** |
||
54 | * @inheritdoc |
||
55 | */ |
||
56 | 28 | public function compile() |
|
57 | { |
||
58 | 28 | return $this->wrappedExpression->compile(); |
|
59 | } |
||
60 | |||
61 | /** |
||
62 | * @param mixed $alias |
||
63 | * |
||
64 | * @return ExprBuilder |
||
65 | */ |
||
66 | 3 | public function alias($alias) |
|
67 | { |
||
68 | 3 | $alias = ExprNormalizer::normalizeExpression($alias); |
|
69 | |||
70 | 3 | return new self(new AliasExpression($this->wrappedExpression, $alias)); |
|
71 | } |
||
72 | |||
73 | /** |
||
74 | * @return ExprBuilder |
||
75 | */ |
||
76 | public function sumNullable() |
||
77 | { |
||
78 | return $this->ifNull('0')->sum(); |
||
79 | } |
||
80 | |||
81 | /** |
||
82 | * @return ExprBuilder |
||
83 | */ |
||
84 | 1 | public function in() |
|
85 | { |
||
86 | 1 | $arguments = ExprNormalizer::normalizeExpression(func_get_args()); |
|
87 | |||
88 | 1 | return new self(new InExpression($this->wrappedExpression, $arguments)); |
|
89 | } |
||
90 | |||
91 | /** |
||
92 | * @return ExprBuilder |
||
93 | */ |
||
94 | public function using() |
||
95 | { |
||
96 | return new self(new UsingExpression($this->wrappedExpression)); |
||
97 | } |
||
98 | |||
99 | /** |
||
100 | * @return ExprBuilder |
||
101 | */ |
||
102 | 1 | public function desc() |
|
103 | { |
||
104 | 1 | return new self(new OrderExpression($this->wrappedExpression, OrderExpression::ORDER_DESC)); |
|
105 | } |
||
106 | |||
107 | /** |
||
108 | * @return ExprBuilder |
||
109 | */ |
||
110 | 1 | public function asc() |
|
111 | { |
||
112 | 1 | return new self(new OrderExpression($this->wrappedExpression, OrderExpression::ORDER_ASC)); |
|
113 | } |
||
114 | |||
115 | /** |
||
116 | * @inheritdoc |
||
117 | */ |
||
118 | 3 | public function conjunction($connector, $expression) |
|
119 | { |
||
120 | 3 | $expression = ExprNormalizer::normalizeExpression($expression); |
|
121 | |||
122 | 3 | return new self(new ConjunctionExpression($this, $connector, $expression)); |
|
123 | } |
||
124 | |||
125 | /** |
||
126 | * @param string $functionName |
||
127 | * @param FunctionCallContext|null $context |
||
128 | * |
||
129 | * @return ExprBuilder |
||
130 | */ |
||
131 | 11 | public function func($functionName, FunctionCallContext $context = null) |
|
135 | |||
136 | ################# |
||
137 | ### FUNCTIONS ### |
||
138 | ################# |
||
139 | |||
140 | /** |
||
141 | * @return ExprBuilder |
||
142 | */ |
||
143 | 1 | public function asci() |
|
144 | { |
||
145 | 1 | return $this->func(FunctionExpression::FUNC_ASCI); |
|
147 | |||
148 | /** |
||
149 | * @return ExprBuilder |
||
150 | */ |
||
151 | public function bin() |
||
155 | |||
156 | /** |
||
157 | * @return ExprBuilder |
||
158 | */ |
||
159 | public function bitLength() |
||
163 | |||
164 | /** |
||
165 | * @param mixed $using |
||
166 | * |
||
167 | * @return ExprBuilder |
||
168 | */ |
||
169 | 1 | public function char($using = null) |
|
181 | |||
182 | /** |
||
183 | * @return ExprBuilder |
||
184 | */ |
||
185 | 1 | public function coalesce() |
|
189 | |||
190 | /** |
||
191 | * @return ExprBuilder |
||
192 | */ |
||
193 | public function concat() |
||
197 | |||
198 | /** |
||
199 | * @return ExprBuilder |
||
200 | */ |
||
201 | public function concatWs() |
||
205 | |||
206 | /** |
||
207 | * @return ExprBuilder |
||
208 | */ |
||
209 | public function elt() |
||
213 | |||
214 | /** |
||
215 | * @return ExprBuilder |
||
216 | */ |
||
217 | 1 | public function exportSet() |
|
221 | |||
222 | /** |
||
223 | * @return ExprBuilder |
||
224 | */ |
||
225 | 1 | public function field() |
|
229 | |||
230 | /** |
||
231 | * @param mixed $expression |
||
232 | * |
||
233 | * @return ExprBuilder |
||
234 | */ |
||
235 | 1 | public function ifNull($expression) |
|
242 | |||
243 | /** |
||
244 | * @return ExprBuilder |
||
245 | */ |
||
246 | 2 | public function max() |
|
250 | |||
251 | /** |
||
252 | * @return ExprBuilder |
||
253 | */ |
||
254 | 4 | public function sum() |
|
258 | } |