1 | <?php |
||
23 | trait QueryTrait |
||
24 | { |
||
25 | |||
26 | /** |
||
27 | * Attach like condition. |
||
28 | * @param mixed $value |
||
29 | * @param string $attribute |
||
30 | * @param string|false $like false, 'like', 'or like', 'not like', 'or not like'. |
||
31 | * @return $this |
||
32 | */ |
||
33 | 10 | protected function likeCondition($value, $attribute, $like = false) |
|
34 | { |
||
35 | 10 | if (!is_string($attribute) || empty($attribute)) { |
|
36 | return $this; |
||
37 | } |
||
38 | 10 | if ($like) { |
|
|
|||
39 | 1 | return $this->andWhere([$like, $attribute, $value]); |
|
40 | } |
||
41 | 10 | return $this->andWhere([$attribute => $value]); |
|
42 | } |
||
43 | |||
44 | /** |
||
45 | * Specify range with $attribute to $query. |
||
46 | * @param ActiveQuery $query |
||
47 | * @param string $attribute |
||
48 | * @param string $start |
||
49 | * @param string $end |
||
50 | * @return $query |
||
51 | */ |
||
52 | protected static function range($query, $attribute, $start = null, $end = null) |
||
62 | } |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: