|
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\WhereProvider; |
|
11
|
|
|
|
|
12
|
|
|
use RDS\Hydrogen\Criteria\Where\Operator; |
|
13
|
|
|
use RDS\Hydrogen\Query; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Trait WhereBetweenProvider |
|
17
|
|
|
* @mixin Query\WhereProvider |
|
18
|
|
|
*/ |
|
19
|
|
|
trait WhereBetweenProvider |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @param string $field |
|
23
|
|
|
* @param mixed $from |
|
24
|
|
|
* @param mixed $to |
|
25
|
|
|
* @return Query|$this|self |
|
26
|
|
|
*/ |
|
27
|
1 |
|
public function orWhereBetween(string $field, $from, $to): self |
|
28
|
|
|
{ |
|
29
|
1 |
|
return $this->or()->whereBetween($field, $from, $to); |
|
|
|
|
|
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @param string $field |
|
34
|
|
|
* @param mixed $from |
|
35
|
|
|
* @param mixed $to |
|
36
|
|
|
* @return Query|$this|self |
|
37
|
|
|
*/ |
|
38
|
2 |
|
public function whereBetween(string $field, $from, $to): self |
|
39
|
|
|
{ |
|
40
|
2 |
|
return $this->where($field, Operator::BTW, [$from, $to]); |
|
|
|
|
|
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @param string $field |
|
45
|
|
|
* @param mixed $from |
|
46
|
|
|
* @param mixed $to |
|
47
|
|
|
* @return Query|$this|self |
|
48
|
|
|
*/ |
|
49
|
1 |
|
public function orWhereNotBetween(string $field, $from, $to): self |
|
50
|
|
|
{ |
|
51
|
1 |
|
return $this->or()->whereNotBetween($field, $from, $to); |
|
|
|
|
|
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @param string $field |
|
56
|
|
|
* @param mixed $from |
|
57
|
|
|
* @param mixed $to |
|
58
|
|
|
* @return Query|$this|self |
|
59
|
|
|
*/ |
|
60
|
2 |
|
public function whereNotBetween(string $field, $from, $to): self |
|
61
|
|
|
{ |
|
62
|
2 |
|
return $this->where($field, Operator::NOT_BTW, [$from, $to]); |
|
|
|
|
|
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idableprovides a methodequalsIdthat in turn relies on the methodgetId(). If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()as an abstract method to the trait will make sure it is available.