1 | <?php |
||
17 | class MappingBuilder |
||
18 | { |
||
19 | /** |
||
20 | * Skip adding default information to certain fields. |
||
21 | * |
||
22 | * @var array |
||
23 | */ |
||
24 | private $skipTypes = array('completion'); |
||
25 | |||
26 | /** |
||
27 | * Builds mappings for an entire index. |
||
28 | * |
||
29 | * @param IndexConfig $indexConfig |
||
30 | * |
||
31 | * @return array |
||
32 | */ |
||
33 | 5 | public function buildIndexMapping(IndexConfig $indexConfig) |
|
53 | |||
54 | /** |
||
55 | * Builds mappings for a single type. |
||
56 | * |
||
57 | * @param TypeConfig $typeConfig |
||
58 | * |
||
59 | * @return array |
||
60 | */ |
||
61 | 6 | public function buildTypeMapping(TypeConfig $typeConfig) |
|
62 | { |
||
63 | 6 | $mapping = $typeConfig->getMapping(); |
|
64 | |||
65 | 6 | if (null !== $typeConfig->getDynamicDateFormats()) { |
|
66 | 5 | $mapping['dynamic_date_formats'] = $typeConfig->getDynamicDateFormats(); |
|
67 | 5 | } |
|
68 | |||
69 | 6 | if (null !== $typeConfig->getDateDetection()) { |
|
70 | 2 | $mapping['date_detection'] = $typeConfig->getDateDetection(); |
|
71 | 2 | } |
|
72 | |||
73 | 6 | if (null !== $typeConfig->getNumericDetection()) { |
|
74 | 2 | $mapping['numeric_detection'] = $typeConfig->getNumericDetection(); |
|
75 | 2 | } |
|
76 | |||
77 | 6 | if ($typeConfig->getAnalyzer()) { |
|
|
|||
78 | $mapping['analyzer'] = $typeConfig->getAnalyzer(); |
||
79 | } |
||
80 | |||
81 | 6 | if ($typeConfig->getDynamic() !== null) { |
|
82 | 2 | $mapping['dynamic'] = $typeConfig->getDynamic(); |
|
83 | 2 | } |
|
84 | |||
85 | 6 | if (isset($mapping['dynamic_templates']) and empty($mapping['dynamic_templates'])) { |
|
86 | 5 | unset($mapping['dynamic_templates']); |
|
87 | 5 | } |
|
88 | |||
89 | 6 | $this->fixProperties($mapping['properties']); |
|
90 | 6 | if (!$mapping['properties']) { |
|
91 | 3 | unset($mapping['properties']); |
|
92 | 3 | } |
|
93 | |||
94 | 6 | if ($typeConfig->getModel()) { |
|
95 | 3 | $mapping['_meta']['model'] = $typeConfig->getModel(); |
|
96 | 3 | } |
|
97 | |||
98 | 6 | unset($mapping['_parent']['identifier'], $mapping['_parent']['property']); |
|
99 | |||
100 | 6 | if (empty($mapping)) { |
|
101 | // Empty mapping, we want it encoded as a {} instead of a [] |
||
102 | $mapping = new \ArrayObject(); |
||
103 | } |
||
104 | |||
105 | 6 | return $mapping; |
|
106 | } |
||
107 | |||
108 | /** |
||
109 | * Fixes any properties and applies basic defaults for any field that does not have |
||
110 | * required options. |
||
111 | * |
||
112 | * @param $properties |
||
113 | */ |
||
114 | 6 | private function fixProperties(&$properties) |
|
133 | } |
||
134 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: