1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Mado\QueryBundle\Queries\Objects; |
4
|
|
|
|
5
|
|
|
use Mado\QueryBundle\Services\StringParser; |
6
|
|
|
use Mado\QueryBundle\Dictionary; |
7
|
|
|
|
8
|
|
|
/** @since class available since release 2.2 */ |
9
|
|
|
final class FilterObject |
10
|
|
|
{ |
11
|
|
|
const FIELD = 0; |
12
|
|
|
|
13
|
|
|
const OPERATOR = 1; |
14
|
|
|
|
15
|
|
|
const POSITION = 2; |
16
|
|
|
|
17
|
|
|
private $rawFilter; |
18
|
|
|
|
19
|
|
|
private $fieldName; |
20
|
|
|
|
21
|
|
|
private $operatorName; |
22
|
|
|
|
23
|
|
|
private $position; |
24
|
|
|
|
25
|
26 |
|
private function __construct(string $rawFilter) |
26
|
|
|
{ |
27
|
26 |
|
$this->setRawFilter($rawFilter); |
28
|
|
|
|
29
|
26 |
|
$explodedRawFilter = explode('|', $rawFilter); |
30
|
26 |
|
if (!isset($explodedRawFilter[self::OPERATOR])) { |
31
|
1 |
|
$explodedRawFilter[self::OPERATOR] = Dictionary::DEFAULT_OPERATOR; |
32
|
|
|
} |
33
|
|
|
|
34
|
26 |
|
$fieldName = $explodedRawFilter[self::FIELD]; |
35
|
26 |
|
$parser = new StringParser(); |
36
|
26 |
|
$this->fieldName = $parser->camelize($fieldName); |
37
|
|
|
|
38
|
26 |
|
$this->operatorName = $explodedRawFilter[self::OPERATOR]; |
39
|
|
|
|
40
|
26 |
|
$position = 0; |
41
|
26 |
|
if (isset($explodedRawFilter[self::POSITION])) { |
42
|
2 |
|
$position = $explodedRawFilter[self::POSITION]; |
43
|
|
|
} |
44
|
|
|
|
45
|
26 |
|
$this->position = $position; |
46
|
26 |
|
} |
47
|
|
|
|
48
|
26 |
|
public static function fromRawFilter(string $filter) : FilterObject |
49
|
|
|
{ |
50
|
26 |
|
return new self($filter); |
51
|
|
|
} |
52
|
|
|
|
53
|
24 |
|
public function getFieldName() : string |
54
|
|
|
{ |
55
|
24 |
|
return $this->fieldName; |
56
|
|
|
} |
57
|
|
|
|
58
|
24 |
|
public function getOperatorName() : string |
59
|
|
|
{ |
60
|
24 |
|
return $this->operatorName; |
61
|
|
|
} |
62
|
|
|
|
63
|
23 |
|
public function isListType() : bool |
64
|
|
|
{ |
65
|
23 |
|
return in_array( |
66
|
23 |
|
$this->getOperatorName(), |
67
|
23 |
|
$listOperators = ['list', 'nlist'] |
68
|
|
|
); |
69
|
|
|
} |
70
|
|
|
|
71
|
11 |
|
public function isFieldEqualityType() : bool |
72
|
|
|
{ |
73
|
11 |
|
return $this->getOperatorName() == 'field_eq'; |
74
|
|
|
} |
75
|
|
|
|
76
|
24 |
|
public function getOperatorMeta() : string |
77
|
|
|
{ |
78
|
24 |
|
return Dictionary::getOperators()[$this->getOperatorName()]['meta']; |
79
|
|
|
} |
80
|
|
|
|
81
|
24 |
|
public function haveOperatorSubstitutionPattern() : bool |
82
|
|
|
{ |
83
|
24 |
|
$operator = Dictionary::getOperators()[$this->getOperatorName()]; |
84
|
|
|
|
85
|
24 |
|
return isset($operator['substitution_pattern']); |
86
|
|
|
} |
87
|
|
|
|
88
|
4 |
|
public function getOperatorsSubstitutionPattern() : string |
89
|
|
|
{ |
90
|
4 |
|
$operator = Dictionary::getOperators()[$this->getOperatorName()]; |
91
|
|
|
|
92
|
4 |
|
return $operator['substitution_pattern']; |
93
|
|
|
} |
94
|
|
|
|
95
|
26 |
|
public function setRawFilter(string $rawFilter) |
96
|
|
|
{ |
97
|
26 |
|
$this->rawFilter = $rawFilter; |
98
|
26 |
|
} |
99
|
|
|
|
100
|
24 |
|
public function getRawFilter() : string |
101
|
|
|
{ |
102
|
24 |
|
return $this->rawFilter; |
103
|
|
|
} |
104
|
|
|
|
105
|
2 |
|
public function getOperator() |
106
|
|
|
{ |
107
|
2 |
|
return $this->operatorName; |
108
|
|
|
} |
109
|
|
|
|
110
|
24 |
|
public function isNullType() : bool |
111
|
|
|
{ |
112
|
24 |
|
return $this->getOperatorName() === 'isnull' || $this->getOperatorName() === 'isnotnull'; |
113
|
|
|
} |
114
|
|
|
|
115
|
13 |
|
public function isListContainsType() : bool |
116
|
|
|
{ |
117
|
13 |
|
return $this->getOperatorName() === 'listcontains'; |
118
|
|
|
} |
119
|
|
|
|
120
|
11 |
|
public function getPosition() |
121
|
|
|
{ |
122
|
11 |
|
return $this->position; |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|