1 | <?php |
||
20 | trait WhereTrait |
||
21 | { |
||
22 | /** |
||
23 | * |
||
24 | * Adds a WHERE condition to the query by AND. |
||
25 | * |
||
26 | * @param string $cond The WHERE condition. |
||
27 | * |
||
28 | * @param array $bind Values to be bound to placeholders |
||
29 | * |
||
30 | * @return $this |
||
31 | * |
||
32 | */ |
||
33 | 65 | public function where($cond, array $bind = []) |
|
38 | |||
39 | /** |
||
40 | * |
||
41 | * Adds a WHERE condition to the query by OR. If the condition has |
||
42 | * ?-placeholders, additional arguments to the method will be bound to |
||
43 | * those placeholders sequentially. |
||
44 | * |
||
45 | * @param string $cond The WHERE condition. |
||
46 | * |
||
47 | * @param array $bind Values to be bound to placeholders |
||
48 | * |
||
49 | * @return $this |
||
50 | * |
||
51 | * @see where() |
||
52 | * |
||
53 | */ |
||
54 | 34 | public function orWhere($cond, array $bind = []) |
|
59 | |||
60 | /** |
||
61 | * |
||
62 | * Adds a WHERE condition with a prepared statement placeholder and value to the query by AND. |
||
63 | * |
||
64 | * @param string $cond the first part of the WHERE condition without the placeholder. e.g. "name = " or "name IN" |
||
65 | * |
||
66 | * @param string $placeholder the placeholder as a string. e.g. ":NAME" or "(:NAMES)" |
||
67 | * |
||
68 | * @param (string|int|float|array) $value the value to be bound to the placeholder. e.g. "John" or ["John", "Eric", "Michael", "Terry"] |
||
69 | * |
||
70 | * @return $this |
||
71 | * |
||
72 | * @throws Exception |
||
73 | * |
||
74 | */ |
||
75 | 5 | public function whereBoundValue(string $cond, string $placeholder, $value) |
|
81 | |||
82 | /** |
||
83 | * |
||
84 | * Adds a WHERE condition with a prepared statement placeholder and value to the query by OR. |
||
85 | * |
||
86 | * @param string $cond the first part of the WHERE condition without the placeholder. e.g. "name = " or "name IN" |
||
87 | * |
||
88 | * @param string $placeholder the placeholder as a string. e.g. ":NAME" or "(:NAMES)" |
||
89 | * |
||
90 | * @param (string|int|float|array) $value the value to be bound to the placeholder. e.g. "John" or ["John", "Eric", "Michael", "Terry"] |
||
91 | * |
||
92 | * @return $this |
||
93 | * |
||
94 | * @throws Exception |
||
95 | * |
||
96 | * @see whereBoundValue() |
||
97 | * |
||
98 | */ |
||
99 | public function orWhereBoundValue(string $cond, string $placeholder, $value) |
||
105 | |||
106 | /** |
||
107 | * Extract the name of PDO placeholders (e.g. "P") of the form ":P" for simple values and "(:P)" for array values. |
||
108 | * |
||
109 | * @param string $placeholder the placeholder specification |
||
110 | * |
||
111 | * @return the placeholder name as string |
||
112 | * |
||
113 | * @throws Exception |
||
114 | * |
||
115 | */ |
||
116 | 5 | protected static function extractNameOrThrow(string $placeholder) { |
|
124 | } |
||
125 |
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.