|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of Hydrogen package. |
|
4
|
|
|
* |
|
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
6
|
|
|
* file that was distributed with this source code. |
|
7
|
|
|
*/ |
|
8
|
|
|
declare(strict_types=1); |
|
9
|
|
|
|
|
10
|
|
|
namespace RDS\Hydrogen\Query; |
|
11
|
|
|
|
|
12
|
|
|
use RDS\Hydrogen\Criteria\Where; |
|
13
|
|
|
use RDS\Hydrogen\Criteria\WhereGroup; |
|
14
|
|
|
use RDS\Hydrogen\Query; |
|
15
|
|
|
use RDS\Hydrogen\Query\WhereProvider\WhereBetweenProvider; |
|
16
|
|
|
use RDS\Hydrogen\Query\WhereProvider\WhereInProvider; |
|
17
|
|
|
use RDS\Hydrogen\Query\WhereProvider\WhereLikeProvider; |
|
18
|
|
|
use RDS\Hydrogen\Query\WhereProvider\WhereNullProvider; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Trait WhereProvider |
|
22
|
|
|
* @mixin Query |
|
23
|
|
|
*/ |
|
24
|
|
|
trait WhereProvider |
|
25
|
|
|
{ |
|
26
|
|
|
use WhereInProvider; |
|
27
|
|
|
use WhereLikeProvider; |
|
28
|
|
|
use WhereNullProvider; |
|
29
|
|
|
use WhereBetweenProvider; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @param string|\Closure $field |
|
33
|
|
|
* @param $valueOrOperator |
|
34
|
|
|
* @param null $value |
|
35
|
|
|
* @return Query|$this|self |
|
36
|
|
|
*/ |
|
37
|
13 |
|
public function orWhere($field, $valueOrOperator = null, $value = null): self |
|
38
|
|
|
{ |
|
39
|
13 |
|
return $this->or->where($field, $valueOrOperator, $value); |
|
|
|
|
|
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @param string|\Closure $field |
|
44
|
|
|
* @param $valueOrOperator |
|
45
|
|
|
* @param null $value |
|
46
|
|
|
* @return Query|$this|self |
|
47
|
|
|
*/ |
|
48
|
41 |
|
public function where($field, $valueOrOperator = null, $value = null): self |
|
49
|
|
|
{ |
|
50
|
41 |
|
if (\is_string($field)) { |
|
51
|
41 |
|
[$operator, $value] = Where::completeMissingParameters($valueOrOperator, $value); |
|
|
|
|
|
|
52
|
|
|
|
|
53
|
41 |
|
return $this->add(new Where($this, $field, $operator, $value, $this->mode())); |
|
|
|
|
|
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
5 |
|
if ($field instanceof \Closure) { |
|
57
|
5 |
|
return $this->add(new WhereGroup($this, $field, $this->mode())); |
|
|
|
|
|
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
$error = \vsprintf('Selection set should be a type of string or Closure, but %s given', [ |
|
61
|
|
|
\studly_case(\gettype($field)), |
|
62
|
|
|
]); |
|
63
|
|
|
|
|
64
|
|
|
throw new \InvalidArgumentException($error); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: