1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Yiisoft\Db\Query\Conditions; |
6
|
|
|
|
7
|
|
|
use Iterator; |
8
|
|
|
use Yiisoft\Db\Exception\InvalidArgumentException; |
9
|
|
|
use Yiisoft\Db\Expression\Expression; |
10
|
|
|
use Yiisoft\Db\Expression\ExpressionInterface; |
11
|
|
|
use Yiisoft\Db\Query\Conditions\Interface\LikeConditionInterface; |
|
|
|
|
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class LikeCondition represents a `LIKE` condition. |
15
|
|
|
*/ |
16
|
|
|
class LikeCondition implements LikeConditionInterface |
17
|
|
|
{ |
18
|
|
|
protected ?array $escapingReplacements = []; |
19
|
|
|
|
20
|
|
|
public function __construct( |
21
|
|
|
private string|Expression $column, |
22
|
|
|
private string $operator, |
23
|
|
|
private array|int|string|Iterator|ExpressionInterface|null $value |
24
|
|
|
) { |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function getColumn(): string|Expression |
28
|
|
|
{ |
29
|
|
|
return $this->column; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function getEscapingReplacements(): ?array |
33
|
|
|
{ |
34
|
|
|
return $this->escapingReplacements; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function getOperator(): string |
38
|
|
|
{ |
39
|
|
|
return $this->operator; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function getValue(): array|int|string|Iterator|ExpressionInterface|null |
43
|
|
|
{ |
44
|
|
|
return $this->value; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function setEscapingReplacements(array|null $escapingReplacements): void |
48
|
|
|
{ |
49
|
|
|
$this->escapingReplacements = $escapingReplacements; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public static function fromArrayDefinition(string $operator, array $operands): self |
53
|
|
|
{ |
54
|
|
|
if (!isset($operands[0], $operands[1])) { |
55
|
|
|
throw new InvalidArgumentException("Operator '$operator' requires two operands."); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
$condition = new static($operands[0], $operator, $operands[1]); |
59
|
|
|
|
60
|
|
|
if (array_key_exists(2, $operands)) { |
61
|
|
|
$condition->setEscapingReplacements($operands[2]); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
return $condition; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|