-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathField.php
More file actions
57 lines (43 loc) · 1.19 KB
/
Field.php
File metadata and controls
57 lines (43 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
declare(strict_types = 1);
namespace Spameri\ElasticQuery\Mapping\Settings\Mapping;
class Field
implements \Spameri\ElasticQuery\Mapping\Settings\Mapping\FieldInterface
{
public function __construct(
private string $name,
private string $type = \Spameri\ElasticQuery\Mapping\AllowedValues::TYPE_KEYWORD,
private \Spameri\ElasticQuery\Mapping\AnalyzerInterface|null $analyzer = null,
private bool|null $fieldData = null,
)
{
if ( ! \in_array($type, \Spameri\ElasticQuery\Mapping\AllowedValues::TYPES, true)) {
throw new \Spameri\ElasticQuery\Exception\InvalidArgumentException(
'Not allowed type see \Spameri\ElasticQuery\Mapping\AllowedValues::TYPES',
);
}
}
public function changeAnalyzer(\Spameri\ElasticQuery\Mapping\AnalyzerInterface $newAnalyzer): void
{
$this->analyzer = $newAnalyzer;
}
public function key(): string
{
return $this->name;
}
public function toArray(): array
{
$array = [
$this->name => [
'type' => $this->type,
],
];
if ($this->analyzer) {
$array[$this->name]['analyzer'] = $this->analyzer->name();
}
if ($this->fieldData !== null) {
$array[$this->name]['fielddata'] = $this->fieldData;
}
return $array;
}
}