1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace AmaTeam\ElasticSearch\API\Entity\Mapping; |
6
|
|
|
|
7
|
|
|
class ClassMappingView implements ClassMappingViewInterface |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* @var string |
11
|
|
|
*/ |
12
|
|
|
private $type; |
13
|
|
|
/** |
14
|
|
|
* @var array |
15
|
|
|
*/ |
16
|
|
|
private $parameters = []; |
17
|
|
|
/** |
18
|
|
|
* @var string[] |
19
|
|
|
*/ |
20
|
|
|
private $ignoredProperties = []; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @return string |
24
|
|
|
*/ |
25
|
|
|
public function getType(): ?string |
26
|
|
|
{ |
27
|
|
|
return $this->type; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param string $type |
32
|
|
|
* @return $this |
33
|
|
|
*/ |
34
|
|
|
public function setType(string $type) |
35
|
|
|
{ |
36
|
|
|
$this->type = $type; |
37
|
|
|
return $this; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @return array |
42
|
|
|
*/ |
43
|
|
|
public function getParameters(): array |
44
|
|
|
{ |
45
|
|
|
return $this->parameters; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function setParameter(string $parameter, $value): ClassMappingViewInterface |
49
|
|
|
{ |
50
|
|
|
$this->parameters[$parameter] = $value; |
51
|
|
|
return $this; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param array $parameters |
56
|
|
|
* @return $this |
57
|
|
|
*/ |
58
|
|
|
public function setParameters(array $parameters) |
59
|
|
|
{ |
60
|
|
|
$this->parameters = $parameters; |
61
|
|
|
return $this; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @return string[] |
66
|
|
|
*/ |
67
|
|
|
public function getIgnoredProperties(): array |
68
|
|
|
{ |
69
|
|
|
return $this->ignoredProperties; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @param string[] $ignoredProperties |
74
|
|
|
* @return $this |
75
|
|
|
*/ |
76
|
|
|
public function setIgnoredProperties(array $ignoredProperties) |
77
|
|
|
{ |
78
|
|
|
$this->ignoredProperties = $ignoredProperties; |
79
|
|
|
return $this; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function addIgnoredProperty(string $property): ClassMappingViewInterface |
83
|
|
|
{ |
84
|
|
|
$this->ignoredProperties[$property] = $property; |
85
|
|
|
return $this; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function removeIgnoredProperty(string $property): ClassMappingView |
89
|
|
|
{ |
90
|
|
|
unset($this->ignoredProperties[$property]); |
91
|
|
|
return $this; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function hasIgnoredProperty(string $property): bool |
95
|
|
|
{ |
96
|
|
|
return isset($this->ignoredProperties[$property]); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public static function merge(ClassMappingViewInterface ...$mappings): ClassMappingView |
100
|
|
|
{ |
101
|
|
|
$target = new ClassMappingView(); |
102
|
|
|
$parameters = []; |
103
|
|
|
foreach ($mappings as $mapping) { |
104
|
|
|
if ($mapping->getType()) { |
|
|
|
|
105
|
|
|
$target->setType($mapping->getType()); |
106
|
|
|
} |
107
|
|
|
foreach ($mapping->getParameters() as $parameter => $value) { |
108
|
|
|
$parameters[$parameter] = $value; |
109
|
|
|
} |
110
|
|
|
$target->setIgnoredProperties($mapping->getIgnoredProperties()); |
111
|
|
|
} |
112
|
|
|
$target->setParameters($parameters); |
113
|
|
|
return $target; |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: