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\Criteria\Where; |
14
|
|
|
use RDS\Hydrogen\Query; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Trait WhereBetweenProvider |
18
|
|
|
* @mixin Query\WhereProvider |
19
|
|
|
*/ |
20
|
|
|
trait WhereBetweenProvider |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @param string $field |
24
|
|
|
* @param mixed $from |
25
|
|
|
* @param mixed $to |
26
|
|
|
* @return Query|$this|self |
27
|
|
|
*/ |
28
|
1 |
|
public function orWhereBetween(string $field, $from, $to): self |
29
|
|
|
{ |
30
|
1 |
|
return $this->or()->whereBetween($field, $from, $to); |
|
|
|
|
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param string $field |
35
|
|
|
* @param mixed $from |
36
|
|
|
* @param mixed $to |
37
|
|
|
* @return Query|$this|self |
38
|
|
|
*/ |
39
|
2 |
|
public function whereBetween(string $field, $from, $to): self |
40
|
|
|
{ |
41
|
2 |
|
return $this->add(new Where($field, Operator::BTW, [$from, $to], $this->mode())); |
|
|
|
|
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param string $field |
46
|
|
|
* @param mixed $from |
47
|
|
|
* @param mixed $to |
48
|
|
|
* @return Query|$this|self |
49
|
|
|
*/ |
50
|
1 |
|
public function orWhereNotBetween(string $field, $from, $to): self |
51
|
|
|
{ |
52
|
1 |
|
return $this->or()->whereNotBetween($field, $from, $to); |
|
|
|
|
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param string $field |
57
|
|
|
* @param mixed $from |
58
|
|
|
* @param mixed $to |
59
|
|
|
* @return Query|$this|self |
60
|
|
|
*/ |
61
|
2 |
|
public function whereNotBetween(string $field, $from, $to): self |
62
|
|
|
{ |
63
|
2 |
|
return $this->add(new Where($field, Operator::NOT_BTW, [$from, $to], $this->mode())); |
|
|
|
|
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
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
Idable
provides a methodequalsId
that 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.