1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace AmaTeam\ElasticSearch\Entity\Mapping; |
6
|
|
|
|
7
|
|
|
use AmaTeam\ElasticSearch\API\Entity\Mapping\PropertyMappingViewInterface; |
8
|
|
|
|
9
|
|
|
class PropertyMappingView implements PropertyMappingViewInterface |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var string|null |
13
|
|
|
*/ |
14
|
|
|
private $type; |
15
|
|
|
/** |
16
|
|
|
* @var string|null |
17
|
|
|
*/ |
18
|
|
|
private $targetClass; |
19
|
|
|
/** |
20
|
|
|
* @var array |
21
|
|
|
*/ |
22
|
|
|
private $parameters = []; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @return null|string |
26
|
|
|
*/ |
27
|
|
|
public function getType(): ?string |
28
|
|
|
{ |
29
|
|
|
return $this->type; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param null|string $type |
34
|
|
|
* @return $this |
35
|
|
|
*/ |
36
|
|
|
public function setType(string $type) |
37
|
|
|
{ |
38
|
|
|
$this->type = $type; |
39
|
|
|
return $this; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @return null|string |
44
|
|
|
*/ |
45
|
|
|
public function getTargetClass(): ?string |
46
|
|
|
{ |
47
|
|
|
return $this->targetClass; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param null|string $targetClass |
52
|
|
|
* @return $this |
53
|
|
|
*/ |
54
|
|
|
public function setTargetClass(string $targetClass) |
55
|
|
|
{ |
56
|
|
|
$this->targetClass = $targetClass; |
57
|
|
|
return $this; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return array |
62
|
|
|
*/ |
63
|
|
|
public function getParameters(): array |
64
|
|
|
{ |
65
|
|
|
return $this->parameters; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param array $parameters |
70
|
|
|
* @return $this |
71
|
|
|
*/ |
72
|
|
|
public function setParameters(array $parameters) |
73
|
|
|
{ |
74
|
|
|
$this->parameters = $parameters; |
75
|
|
|
return $this; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function setParameter(string $name, $value): PropertyMappingView |
79
|
|
|
{ |
80
|
|
|
$this->parameters[$name] = $value; |
81
|
|
|
return $this; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public static function merge(PropertyMappingViewInterface ...$views): PropertyMappingView |
85
|
|
|
{ |
86
|
|
|
$target = new PropertyMappingView(); |
87
|
|
|
foreach ($views as $view) { |
88
|
|
|
if ($view->getType()) { |
|
|
|
|
89
|
|
|
$target->setType($view->getType()); |
90
|
|
|
} |
91
|
|
|
if ($view->getTargetClass()) { |
|
|
|
|
92
|
|
|
$target->setTargetClass($view->getTargetClass()); |
93
|
|
|
} |
94
|
|
|
foreach ($view->getParameters() as $parameter => $value) { |
95
|
|
|
$target->setParameter($parameter, $value); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
return $target; |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
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: