File tree Expand file tree Collapse file tree 1 file changed +58
-0
lines changed
src/Mapping/Settings/Mapping Expand file tree Collapse file tree 1 file changed +58
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php declare (strict_types = 1 );
2+
3+ namespace Spameri \ElasticQuery \Mapping \Settings \Mapping ;
4+
5+ class NestedObject implements \Spameri \ElasticQuery \Mapping \Settings \Mapping \FieldInterface
6+ {
7+
8+ /**
9+ * @var string
10+ */
11+ private $ name ;
12+
13+ /**
14+ * @var \Spameri\ElasticQuery\Mapping\Settings\Mapping\FieldCollection
15+ */
16+ private $ fields ;
17+
18+
19+ public function __construct (
20+ string $ name ,
21+ \Spameri \ElasticQuery \Mapping \Settings \Mapping \FieldCollection $ fields
22+ )
23+ {
24+ $ this ->name = $ name ;
25+ $ this ->fields = $ fields ;
26+ }
27+
28+
29+ public function key (): string
30+ {
31+ return $ this ->name ;
32+ }
33+
34+
35+ public function toArray (): array
36+ {
37+ $ fields = [];
38+ /** @var \Spameri\ElasticQuery\Mapping\Settings\Mapping\FieldInterface $field */
39+ foreach ($ this ->fields as $ field ) {
40+ if ($ field instanceof \Spameri \ElasticQuery \Mapping \Settings \Mapping \FieldObject) {
41+ $ fields [$ field ->key ()] = $ field ->toArray ();
42+ continue ;
43+ }
44+ if ($ field instanceof \Spameri \ElasticQuery \Mapping \Settings \Mapping \FieldCollection) {
45+ $ fields [$ field ->key ()] = $ field ->toArray ();
46+ continue ;
47+ }
48+
49+ $ fields [$ field ->key ()] = $ field ->toArray ()[$ field ->key ()];
50+ }
51+
52+ return [
53+ 'properties ' => $ fields ,
54+ 'type ' => 'nested ' ,
55+ ];
56+ }
57+
58+ }
You can’t perform that action at this time.
0 commit comments