1 | <?php |
||
23 | trait QueryTrait |
||
24 | { |
||
25 | /** |
||
26 | * Attach like condition. |
||
27 | * @param mixed $value |
||
28 | * @param string $attribute |
||
29 | * @param string|false $like false, 'like', 'or like', 'not like', 'or not like'. |
||
30 | * @return $this |
||
31 | */ |
||
32 | 30 | protected function likeCondition($value, $attribute, $like = false) |
|
33 | { |
||
34 | 30 | if (!is_string($attribute) || empty($attribute)) { |
|
35 | 2 | return $this; |
|
36 | } |
||
37 | 30 | if ($like !== false) { |
|
38 | 8 | return $this->andWhere([$like, $attribute, $value]); |
|
|
|||
39 | } |
||
40 | 30 | return $this->andWhere([$attribute => $value]); |
|
41 | } |
||
42 | |||
43 | /** |
||
44 | * Specify range with $attribute to $query. |
||
45 | * @param ActiveQuery $query |
||
46 | * @param string $attribute |
||
47 | * @param string $start |
||
48 | * @param string $end |
||
49 | * @return $query |
||
50 | */ |
||
51 | 4 | protected static function range($query, $attribute, $start = null, $end = null) |
|
61 | } |
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.