1 | <?php |
||
18 | class MappingBuilder |
||
19 | { |
||
20 | /** |
||
21 | * Builds mappings for an entire index. |
||
22 | * |
||
23 | * @param IndexConfigInterface $indexConfig |
||
24 | * |
||
25 | * @return array |
||
26 | */ |
||
27 | 8 | public function buildIndexMapping(IndexConfigInterface $indexConfig) |
|
47 | |||
48 | /** |
||
49 | * Builds mappings for an entire index template. |
||
50 | * |
||
51 | * @param IndexTemplateConfig $indexTemplateConfig |
||
52 | * |
||
53 | * @return array |
||
54 | */ |
||
55 | 5 | public function buildIndexTemplateMapping(IndexTemplateConfig $indexTemplateConfig) |
|
62 | |||
63 | /** |
||
64 | * Builds mappings for a single type. |
||
65 | * |
||
66 | * @param TypeConfig $typeConfig |
||
67 | * |
||
68 | * @return array |
||
69 | */ |
||
70 | 9 | public function buildTypeMapping(?string $model, TypeConfig $typeConfig) |
|
71 | { |
||
72 | 9 | $mapping = $typeConfig->getMapping(); |
|
73 | |||
74 | 9 | if (null !== $typeConfig->getDynamicDateFormats()) { |
|
75 | 7 | $mapping['dynamic_date_formats'] = $typeConfig->getDynamicDateFormats(); |
|
76 | } |
||
77 | |||
78 | 9 | if (null !== $typeConfig->getDateDetection()) { |
|
79 | 1 | $mapping['date_detection'] = $typeConfig->getDateDetection(); |
|
80 | } |
||
81 | |||
82 | 9 | if (null !== $typeConfig->getNumericDetection()) { |
|
83 | 1 | $mapping['numeric_detection'] = $typeConfig->getNumericDetection(); |
|
84 | } |
||
85 | |||
86 | 9 | if ($typeConfig->getAnalyzer()) { |
|
87 | $mapping['analyzer'] = $typeConfig->getAnalyzer(); |
||
88 | } |
||
89 | |||
90 | 9 | if (null !== $typeConfig->getDynamic()) { |
|
91 | 1 | $mapping['dynamic'] = $typeConfig->getDynamic(); |
|
92 | } |
||
93 | |||
94 | 9 | if (isset($mapping['dynamic_templates']) and empty($mapping['dynamic_templates'])) { |
|
95 | 6 | unset($mapping['dynamic_templates']); |
|
96 | } |
||
97 | |||
98 | 9 | $this->fixProperties($mapping['properties']); |
|
99 | 9 | if (!$mapping['properties']) { |
|
100 | unset($mapping['properties']); |
||
101 | } |
||
102 | |||
103 | 9 | if ($model) { |
|
104 | $mapping['_meta']['model'] = $model; |
||
105 | } |
||
106 | |||
107 | 9 | if (empty($mapping)) { |
|
108 | // Empty mapping, we want it encoded as a {} instead of a [] |
||
109 | $mapping = new \ArrayObject(); |
||
110 | } |
||
111 | |||
112 | 9 | return $mapping; |
|
113 | } |
||
114 | |||
115 | /** |
||
116 | * Fixes any properties and applies basic defaults for any field that does not have |
||
117 | * required options. |
||
118 | * |
||
119 | * @param $properties |
||
120 | */ |
||
121 | 9 | private function fixProperties(&$properties) |
|
137 | } |
||
138 |