1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Mado\QueryBundle\Queries\Objects; |
4
|
|
|
|
5
|
|
|
use Mado\QueryBundle\Services\StringParser; |
6
|
|
|
use Mado\QueryBundle\Dictionary; |
7
|
|
|
|
8
|
|
|
final class FilterObject |
9
|
|
|
{ |
10
|
|
|
private $fieldName; |
11
|
|
|
|
12
|
|
|
private $operatorName; |
13
|
|
|
|
14
|
|
|
private function __construct(string $filter) |
15
|
|
|
{ |
16
|
|
|
$explodedFilter = explode('|', $filter); |
17
|
|
|
if (!isset($explodedFilter[1])) { |
18
|
|
|
$explodedFilter[1] = 'eq'; |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
$fieldName = $explodedFilter[0]; |
22
|
|
|
$parser = new StringParser(); |
23
|
|
|
$this->fieldName = $parser->camelize($fieldName); |
24
|
|
|
|
25
|
|
|
$this->operatorName = $explodedFilter[1]; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public static function fromRawFilter(string $filter) : FilterObject |
29
|
|
|
{ |
30
|
|
|
return new self($filter); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function getFieldName() : string |
34
|
|
|
{ |
35
|
|
|
return $this->fieldName; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function getOperatorName() : string |
39
|
|
|
{ |
40
|
|
|
return $this->operatorName; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function isListType() : bool |
44
|
|
|
{ |
45
|
|
|
return $this->getOperatorName() == 'list' |
46
|
|
|
|| $this->getOperatorName() == 'nlist'; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function getOperatorMeta() : string |
50
|
|
|
{ |
51
|
|
|
return Dictionary::getOperators()[$this->getOperatorName()]['meta']; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function haveOperatorSubstitutionPattern() : bool |
55
|
|
|
{ |
56
|
|
|
$operator = Dictionary::getOperators()[$this->getOperatorName()]; |
57
|
|
|
|
58
|
|
|
return isset($operator['substitution_pattern']); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function getOperatorsSubstitutionPattern() : string |
62
|
|
|
{ |
63
|
|
|
$operator = Dictionary::getOperators()[$this->getOperatorName()]; |
64
|
|
|
|
65
|
|
|
return $operator['substitution_pattern']; |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|