@@ 117-147 (lines=31) @@ | ||
114 | protected $isTheFirst; |
|
115 | } |
|
116 | ||
117 | class NextWhereRule extends WhereRule |
|
118 | { |
|
119 | /** |
|
120 | * orWhere('a=?', 1) => "OR a=1" |
|
121 | * orWhere('a=?', Sql::raw('now()')) => "OR a=now()" |
|
122 | * orWhere('a IN (?)', [1, 2]) => "OR a IN (1,2)" |
|
123 | * orWhere([ |
|
124 | * 'a'=>1, |
|
125 | * 'b'=>['IN'=>[1,2]] |
|
126 | * 'c'=>['BETWEEN'=>[1,2]] |
|
127 | * 'd'=>['<>'=>1] |
|
128 | * ]) |
|
129 | * => |
|
130 | * "OR (a=1 AND b IN(1,2) AND c BETWEEN 1 AND 2 AND d<>1)" |
|
131 | * |
|
132 | * @param string|array|callable $conditions |
|
133 | * @param mixed $_ |
|
134 | * @return WhereRule |
|
135 | */ |
|
136 | public function orWhere($conditions=null, $_=null) { |
|
137 | if(is_callable($conditions)){ |
|
138 | $callback = function ($context)use($conditions){ |
|
139 | $rule = new ScopedQuery($context); |
|
140 | $conditions($rule); |
|
141 | }; |
|
142 | $conditions = $callback; |
|
143 | } |
|
144 | WhereImpl::where($this->context, 'OR', $conditions, array_slice(func_get_args(), 1)); |
|
145 | return new WhereRule($this->context, false); |
|
146 | } |
|
147 | } |
|
148 | ||
149 | class ScopedQuery extends BasicRule |
|
150 | { |
|
@@ 182-201 (lines=20) @@ | ||
179 | protected $isTheFirst; |
|
180 | } |
|
181 | ||
182 | class NextScopedQuery extends ScopedQuery |
|
183 | { |
|
184 | /** |
|
185 | * @param $expr |
|
186 | * @param null $_ |
|
187 | * @return ScopedQuery |
|
188 | */ |
|
189 | public function orWhere($expr, $_= null){ |
|
190 | if(is_callable($expr)){ |
|
191 | $callback = function ($context)use($expr){ |
|
192 | $rule = new ScopedQuery($context, true); |
|
193 | $expr($rule); |
|
194 | }; |
|
195 | $expr = $callback; |
|
196 | } |
|
197 | WhereImpl::where($this->context, 'OR', $expr, array_slice(func_get_args(), 1)); |
|
198 | return new NextScopedQuery($this->context, false); |
|
199 | } |
|
200 | ||
201 | } |
@@ 286-319 (lines=34) @@ | ||
283 | } |
|
284 | ||
285 | ||
286 | class NextWhereRule extends WhereRule |
|
287 | { |
|
288 | /** |
|
289 | * orWhere('a=?', 1) => "OR a=1" |
|
290 | * orWhere('a=?', Sql::raw('now()')) => "OR a=now()" |
|
291 | * orWhere('a IN (?)', [1, 2]) => "OR a IN (1,2)" |
|
292 | * orWhere([ |
|
293 | * 'a'=>1, |
|
294 | * 'b'=>['IN'=>[1,2]] |
|
295 | * 'c'=>['BETWEEN'=>[1,2]] |
|
296 | * 'd'=>['<>'=>1] |
|
297 | * ]) |
|
298 | * => |
|
299 | * "OR (a=1 AND b IN(1,2) AND c BETWEEN 1 AND 2 AND d<>1)" |
|
300 | * |
|
301 | * @param string|array|callable $conditions |
|
302 | * @param mixed $_ |
|
303 | * @return \PhpBoot\DB\rules\select\NextWhereRule |
|
304 | * |
|
305 | * @TODO orWhere 只能跟在 Where 后 |
|
306 | */ |
|
307 | public function orWhere($conditions=null, $_=null) { |
|
308 | if(is_callable($conditions)){ |
|
309 | $callback = function ($context)use($conditions){ |
|
310 | $rule = new ScopedQuery($context); |
|
311 | $conditions($rule); |
|
312 | }; |
|
313 | $conditions = $callback; |
|
314 | } |
|
315 | WhereImpl::where($this->context, 'OR', $conditions, array_slice(func_get_args(), 1)); |
|
316 | return new NextWhereRule($this->context, false); |
|
317 | } |
|
318 | ||
319 | } |
|
320 | ||
321 | class JoinRule extends WhereRule |
|
322 | { |