1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* This file is part of Aura for PHP. |
5
|
|
|
* |
6
|
|
|
* @license http://opensource.org/licenses/bsd-license.php BSD |
7
|
|
|
* |
8
|
|
|
*/ |
9
|
|
|
namespace Aura\SqlQuery\Common; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* |
13
|
|
|
* Common code for WHERE clauses. |
14
|
|
|
* |
15
|
|
|
* @package Aura.SqlQuery |
16
|
|
|
* |
17
|
|
|
*/ |
18
|
|
|
trait WhereTrait |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* |
22
|
|
|
* Adds a WHERE condition to the query by AND. If the condition has |
23
|
|
|
* ?-placeholders, additional arguments to the method will be bound to |
24
|
|
|
* those placeholders sequentially. |
25
|
|
|
* |
26
|
|
|
* @param string $cond The WHERE condition. |
27
|
|
|
* @param mixed ...$bind arguments to be bound to placeholders |
28
|
|
|
* |
29
|
|
|
* @return $this |
30
|
|
|
* |
31
|
|
|
*/ |
32
|
55 |
|
public function where($cond, ...$bind) |
33
|
|
|
{ |
34
|
55 |
|
$this->addWhere('AND', $cond, ...$bind); |
35
|
55 |
|
return $this; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* |
40
|
|
|
* Adds a WHERE condition to the query by OR. If the condition has |
41
|
|
|
* ?-placeholders, additional arguments to the method will be bound to |
42
|
|
|
* those placeholders sequentially. |
43
|
|
|
* |
44
|
|
|
* @param string $cond The WHERE condition. |
45
|
|
|
* @param mixed ...$bind arguments to be bound to placeholders |
46
|
|
|
* |
47
|
|
|
* @return $this |
48
|
|
|
* |
49
|
|
|
* @see where() |
50
|
|
|
* |
51
|
|
|
*/ |
52
|
29 |
|
public function orWhere($cond, ...$bind) |
53
|
|
|
{ |
54
|
29 |
|
$this->addWhere('OR', $cond, ...$bind); |
55
|
29 |
|
return $this; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* |
60
|
|
|
* Adds a WHERE condition to the query by AND or OR. If the condition has |
61
|
|
|
* ?-placeholders, additional arguments to the method will be bound to |
62
|
|
|
* those placeholders sequentially. |
63
|
|
|
* |
64
|
|
|
* @param string $andor Add the condition using this operator, typically |
65
|
|
|
* 'AND' or 'OR'. |
66
|
|
|
* @param string $cond The WHERE condition. |
67
|
|
|
* @param mixed ...$bind arguments to bind to placeholders |
68
|
|
|
* |
69
|
|
|
* @return $this |
70
|
|
|
* |
71
|
|
|
*/ |
72
|
|
|
abstract protected function addWhere($andor, $cond, ...$bind); |
73
|
|
|
} |
74
|
|
|
|