Repository navigation
Expand file tree
/
Copy pathIn.php
More file actions
102 lines (86 loc) · 2.71 KB
/
Copy pathIn.php
File metadata and controls
102 lines (86 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
declare(strict_types=1);
namespace PhpDb\Sql\Predicate;
use Override;
use PhpDb\Sql\AbstractExpression;
use PhpDb\Sql\Argument\Identifier;
use PhpDb\Sql\Argument\Select as ArgumentSelect;
use PhpDb\Sql\Argument\Values;
use PhpDb\Sql\ArgumentInterface;
use PhpDb\Sql\Exception\InvalidArgumentException;
use PhpDb\Sql\Select;
class In extends AbstractExpression implements PredicateInterface
{
protected ?ArgumentInterface $identifier = null;
protected ?ArgumentInterface $valueSet = null;
protected string $operator = 'IN';
/**
* Constructor
*/
public function __construct(
null|string|ArgumentInterface $identifier = null,
null|array|Select|ArgumentInterface $valueSet = null
) {
if ($identifier !== null) {
$this->setIdentifier($identifier);
}
if ($valueSet !== null) {
$this->setValueSet($valueSet);
}
}
/**
* Set identifier for comparison
*/
public function setIdentifier(string|ArgumentInterface $identifier): static
{
$this->identifier = $identifier instanceof ArgumentInterface
? $identifier
: new Identifier($identifier);
return $this;
}
/**
* Get identifier of comparison
*/
public function getIdentifier(): ?ArgumentInterface
{
return $this->identifier;
}
/**
* Set set of values for IN comparison
*/
public function setValueSet(array|Select|ArgumentInterface $valueSet): static
{
if ($valueSet instanceof ArgumentInterface) {
$this->valueSet = $valueSet;
} elseif ($valueSet instanceof Select) {
$this->valueSet = new ArgumentSelect($valueSet);
} else {
$this->valueSet = new Values($valueSet);
}
return $this;
}
/**
* Gets set of values in IN comparison
*/
public function getValueSet(): ?ArgumentInterface
{
return $this->valueSet;
}
/** @inheritDoc */
#[Override]
public function getExpressionData(): array
{
if (! $this->identifier instanceof ArgumentInterface) {
throw new InvalidArgumentException('Identifier must be specified');
}
if (! $this->valueSet instanceof ArgumentInterface) {
throw new InvalidArgumentException('Value set must be provided for IN predicate');
}
$identifierSpec = $this->identifier->getSpecification();
$valueSetSpec = $this->valueSet->getSpecification();
return [
'spec' => $this->specification ?? "{$identifierSpec} {$this->operator} {$valueSetSpec}",
'values' => [$this->identifier, $this->valueSet],
];
}
}