Operators.php
2.09 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
<?php
namespace ACP\Search;
use AC\Config;
use LogicException;
final class Operators extends Config
{
public const EQ = '=';
public const NEQ = '!=';
public const GT = '>';
public const GTE = '>=';
public const LT = '<';
public const LTE = '<=';
public const CONTAINS = 'CONTAINS';
public const NOT_CONTAINS = 'NOT CONTAINS';
public const BEGINS_WITH = 'BEGINS WITH';
public const ENDS_WITH = 'ENDS WITH';
public const IN = 'IN';
public const NOT_IN = 'NOT IN';
public const BETWEEN = 'BETWEEN';
public const IS_EMPTY = 'IS EMPTY';
public const NOT_IS_EMPTY = 'NOT IS EMPTY';
public const TODAY = 'TODAY';
public const PAST = 'PAST';
public const FUTURE = 'FUTURE';
public const LT_DAYS_AGO = 'LT_DAYS_AGO';
public const GT_DAYS_AGO = 'GT_DAYS_AGO';
public const WITHIN_DAYS = 'WITHIN_DAYS';
public const CURRENT_USER = 'CURRENT_USER';
public function __construct(array $operators, bool $order = true)
{
if ($order) {
$operators = array_intersect($this->get_operators(), $operators);
}
parent::__construct($operators);
}
protected function get_operators(): array
{
return [
self::EQ,
self::NEQ,
self::GT,
self::GTE,
self::LT,
self::LTE,
self::CONTAINS,
self::NOT_CONTAINS,
self::BEGINS_WITH,
self::ENDS_WITH,
self::IN,
self::NOT_IN,
self::BETWEEN,
self::IS_EMPTY,
self::NOT_IS_EMPTY,
self::TODAY,
self::PAST,
self::FUTURE,
self::LT_DAYS_AGO,
self::GT_DAYS_AGO,
self::WITHIN_DAYS,
self::CURRENT_USER,
];
}
protected function validate_config(): void
{
$operators = $this->get_operators();
foreach ($this as $operator) {
if ( ! in_array($operator, $operators, true)) {
throw new LogicException('Invalid operator found.');
}
}
}
}