-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathSubFields.php
More file actions
83 lines (62 loc) · 1.71 KB
/
Copy pathSubFields.php
File metadata and controls
83 lines (62 loc) · 1.71 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php declare(strict_types = 1);
namespace Spameri\ElasticQuery\Mapping\Settings\Mapping;
class SubFields
implements \Spameri\ElasticQuery\Mapping\Settings\Mapping\FieldInterface
{
/**
* @var string
*/
private $name;
/**
* @var string
*/
private $type;
/**
* @var \Spameri\ElasticQuery\Mapping\Settings\Mapping\FieldCollection
*/
private $fields;
public function __construct(
string $name,
string $type = \Spameri\ElasticQuery\Mapping\AllowedValues::TYPE_KEYWORD,
?\Spameri\ElasticQuery\Mapping\Settings\Mapping\FieldCollection $fields = NULL
)
{
$this->name = $name;
if ($fields === NULL) {
$fields = new \Spameri\ElasticQuery\Mapping\Settings\Mapping\FieldCollection();
}
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'
);
}
$this->type = $type;
$this->fields = $fields;
}
public function key(): string
{
return $this->name;
}
public function getFields(): \Spameri\ElasticQuery\Mapping\Settings\Mapping\FieldCollection
{
return $this->fields;
}
public function addMappingField(\Spameri\ElasticQuery\Mapping\Settings\Mapping\Field $field): void
{
$this->fields->add($field);
}
public function removeMappingField(string $field): void
{
$this->fields->remove($field);
}
public function toArray(): array
{
$array['fields'] = [];
$array['type'] = $this->type;
/** @var \Spameri\ElasticQuery\Mapping\Settings\Mapping\Field $field */
foreach ($this->fields as $field) {
$array['fields'][$field->key()] = $field->toArray()[$field->key()];
}
return $array;
}
}