File tree Expand file tree Collapse file tree 2 files changed +75
-3
lines changed
Expand file tree Collapse file tree 2 files changed +75
-3
lines changed Original file line number Diff line number Diff line change @@ -64,9 +64,7 @@ public function toArray(): array
6464
6565 return [
6666 'mappings ' => [
67- $ this ->indexName => [
68- 'properties ' => $ fields ,
69- ],
67+ 'properties ' => $ fields ,
7068 ],
7169 ];
7270 }
Original file line number Diff line number Diff line change 1+ <?php declare (strict_types = 1 );
2+
3+ namespace Spameri \ElasticQuery \Mapping \Settings ;
4+
5+ class Mapping implements \Spameri \ElasticQuery \Entity \ArrayInterface
6+ {
7+
8+ /**
9+ * @var string
10+ */
11+ private $ indexName ;
12+
13+ /**
14+ * @var \Spameri\ElasticQuery\Mapping\Settings\Mapping\FieldCollection
15+ */
16+ private $ fields ;
17+
18+
19+ public function __construct (
20+ string $ indexName ,
21+ ?\Spameri \ElasticQuery \Mapping \Settings \Mapping \FieldCollection $ fields = NULL
22+ )
23+ {
24+ $ this ->indexName = $ indexName ;
25+
26+ if ($ fields === NULL ) {
27+ $ fields = new \Spameri \ElasticQuery \Mapping \Settings \Mapping \FieldCollection ();
28+ }
29+
30+ $ this ->fields = $ fields ;
31+ }
32+
33+
34+ public function addField (\Spameri \ElasticQuery \Mapping \Settings \Mapping \Field $ field ): void
35+ {
36+ $ this ->fields ->add ($ field );
37+ }
38+
39+
40+ public function addFieldObject (\Spameri \ElasticQuery \Mapping \Settings \Mapping \FieldObject $ fieldObject ): void
41+ {
42+ $ this ->fields ->add ($ fieldObject );
43+ }
44+
45+
46+ public function addSubField (\Spameri \ElasticQuery \Mapping \Settings \Mapping \SubFields $ subFields ): void
47+ {
48+ $ this ->fields ->add ($ subFields );
49+ }
50+
51+
52+ public function toArray (): array
53+ {
54+ $ fields = [];
55+ /** @var \Spameri\ElasticQuery\Mapping\Settings\Mapping\FieldInterface $field */
56+ foreach ($ this ->fields as $ field ) {
57+ if ($ field instanceof \Spameri \ElasticQuery \Mapping \Settings \Mapping \SubFields) {
58+ $ fields [$ field ->key ()] = $ field ->toArray ();
59+
60+ } else {
61+ $ fields [$ field ->key ()] = $ field ->toArray ()[$ field ->key ()];
62+ }
63+ }
64+
65+ return [
66+ 'mappings ' => [
67+ $ this ->indexName => [
68+ 'properties ' => $ fields ,
69+ ],
70+ ],
71+ ];
72+ }
73+
74+ }
You can’t perform that action at this time.
0 commit comments