1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace AmaTeam\ElasticSearch\Entity\Indexing; |
6
|
|
|
|
7
|
|
|
use AmaTeam\ElasticSearch\API\Entity\Indexing\IndexingInterface; |
8
|
|
|
|
9
|
|
|
class Indexing implements IndexingInterface |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var string[] |
13
|
|
|
*/ |
14
|
|
|
private $readIndices = []; |
15
|
|
|
/** |
16
|
|
|
* @var string[] |
17
|
|
|
*/ |
18
|
|
|
private $writeIndices = []; |
19
|
|
|
/** |
20
|
|
|
* TODO: move default value somewhere |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
private $type = 'doc'; |
24
|
|
|
/** |
25
|
|
|
* @var array |
26
|
|
|
*/ |
27
|
|
|
private $options = []; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @return string[] |
31
|
|
|
*/ |
32
|
|
|
public function getReadIndices(): array |
33
|
|
|
{ |
34
|
|
|
return $this->readIndices; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param string[] $readIndices |
39
|
|
|
* @return $this |
40
|
|
|
*/ |
41
|
|
|
public function setReadIndices(array $readIndices) |
42
|
|
|
{ |
43
|
|
|
$this->readIndices = $readIndices; |
44
|
|
|
return $this; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @return string[] |
49
|
|
|
*/ |
50
|
|
|
public function getWriteIndices(): array |
51
|
|
|
{ |
52
|
|
|
return $this->writeIndices; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param string[] $writeIndices |
57
|
|
|
* @return $this |
58
|
|
|
*/ |
59
|
|
|
public function setWriteIndices(array $writeIndices) |
60
|
|
|
{ |
61
|
|
|
$this->writeIndices = $writeIndices; |
62
|
|
|
return $this; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @return string |
67
|
|
|
*/ |
68
|
|
|
public function getType(): string |
69
|
|
|
{ |
70
|
|
|
return $this->type; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @param string $type |
75
|
|
|
* @return $this |
76
|
|
|
*/ |
77
|
|
|
public function setType(string $type) |
78
|
|
|
{ |
79
|
|
|
$this->type = $type; |
80
|
|
|
return $this; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @return array |
85
|
|
|
*/ |
86
|
|
|
public function getOptions(): array |
87
|
|
|
{ |
88
|
|
|
return $this->options; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @param array $options |
93
|
|
|
* @return $this |
94
|
|
|
*/ |
95
|
|
|
public function setOptions(array $options) |
96
|
|
|
{ |
97
|
|
|
$this->options = $options; |
98
|
|
|
return $this; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public static function from(IndexingInterface $other): Indexing |
102
|
|
|
{ |
103
|
|
|
$target = new static(); |
104
|
|
|
if ($other->getType()) { |
105
|
|
|
$target->setType($other->getType()); |
106
|
|
|
} |
107
|
|
|
if ($other->getOptions()) { |
108
|
|
|
$target->setOptions($other->getOptions()); |
109
|
|
|
} |
110
|
|
|
if ($other->getReadIndices()) { |
111
|
|
|
$target->setReadIndices($other->getReadIndices()); |
112
|
|
|
} |
113
|
|
|
if ($other->getWriteIndices()) { |
114
|
|
|
$target->setWriteIndices($other->getWriteIndices()); |
115
|
|
|
} |
116
|
|
|
return $target; |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|