|
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.1 */ |
|
9
|
|
|
final class FilterObject |
|
10
|
|
|
{ |
|
11
|
|
|
private $rawFilter; |
|
12
|
|
|
|
|
13
|
|
|
private $fieldName; |
|
14
|
|
|
|
|
15
|
|
|
private $operatorName; |
|
16
|
|
|
|
|
17
|
|
|
private function __construct(string $rawFilter) |
|
18
|
|
|
{ |
|
19
|
|
|
$this->setRawFilter($rawFilter); |
|
20
|
|
|
|
|
21
|
|
|
$explodedFilter = explode('|', $rawFilter); |
|
22
|
|
|
if (!isset($explodedFilter[1])) { |
|
23
|
|
|
$explodedFilter[1] = 'eq'; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
$fieldName = $explodedFilter[0]; |
|
27
|
|
|
$parser = new StringParser(); |
|
28
|
|
|
$this->fieldName = $parser->camelize($fieldName); |
|
29
|
|
|
|
|
30
|
|
|
$this->operatorName = $explodedFilter[1]; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public static function fromRawFilter(string $filter) : FilterObject |
|
34
|
|
|
{ |
|
35
|
|
|
return new self($filter); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function getFieldName() : string |
|
39
|
|
|
{ |
|
40
|
|
|
return $this->fieldName; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function getOperatorName() : string |
|
44
|
|
|
{ |
|
45
|
|
|
return $this->operatorName; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function isListType() : bool |
|
49
|
|
|
{ |
|
50
|
|
|
return $this->getOperatorName() == 'list' |
|
51
|
|
|
|| $this->getOperatorName() == 'nlist'; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function isFieldEqualityType() |
|
55
|
|
|
{ |
|
56
|
|
|
return $this->getOperatorName() == 'field_eq'; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function getOperatorMeta() : string |
|
60
|
|
|
{ |
|
61
|
|
|
return Dictionary::getOperators()[$this->getOperatorName()]['meta']; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function haveOperatorSubstitutionPattern() : bool |
|
65
|
|
|
{ |
|
66
|
|
|
$operator = Dictionary::getOperators()[$this->getOperatorName()]; |
|
67
|
|
|
|
|
68
|
|
|
return isset($operator['substitution_pattern']); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function getOperatorsSubstitutionPattern() : string |
|
72
|
|
|
{ |
|
73
|
|
|
$operator = Dictionary::getOperators()[$this->getOperatorName()]; |
|
74
|
|
|
|
|
75
|
|
|
return $operator['substitution_pattern']; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function setRawFilter(string $rawFilter) |
|
79
|
|
|
{ |
|
80
|
|
|
$this->rawFilter = $rawFilter; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
public function getRawFilter() : string |
|
84
|
|
|
{ |
|
85
|
|
|
return $this->rawFilter; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function getOperator() |
|
89
|
|
|
{ |
|
90
|
|
|
return $this->operatorName; |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|