SerializedComparisonFactory.php
1.16 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
<?php
namespace ACP\Search\Helper\MetaQuery;
use ACP\Search\Operators;
use ACP\Search\Value;
use LogicException;
final class SerializedComparisonFactory
{
public static function create(string $key, string $operator, Value $value): Comparison
{
$value = new Value(
serialize($value->get_value()),
$value->get_type()
);
$operators = [
Operators::EQ => 'LIKE',
Operators::CURRENT_USER => 'LIKE',
Operators::NEQ => 'NOT LIKE',
Operators::CONTAINS => 'LIKE',
Operators::NOT_CONTAINS => 'NOT LIKE',
];
if (array_key_exists($operator, $operators)) {
return new Comparison($key, $operators[$operator], $value);
}
$operators = [
Operators::IS_EMPTY => 'IsEmpty',
Operators::NOT_IS_EMPTY => 'NotEmpty',
];
if ( ! array_key_exists($operator, $operators)) {
throw new LogicException('Unsupported operator found.');
}
$class = __NAMESPACE__ . '\Comparison\\' . $operators[$operator];
return new $class($key, $value);
}
}