diff --git a/src/Command/GenCommand.php b/src/Command/GenCommand.php index fb1cea5..e11b46b 100644 --- a/src/Command/GenCommand.php +++ b/src/Command/GenCommand.php @@ -101,6 +101,14 @@ public function createModel(string $model, string $index): int $code = str_replace('__MODEL__', $modelName, $code); $code = str_replace('__INDEX__', $index, $code); + $mapping = $mapping[$index]['mappings']['properties']; + $properties = ''; + foreach ($mapping as $property => $item) { + $properties .= "'{$property}' => ['type' => '{$item['type']}']," . PHP_EOL; + } + + $code = str_replace('__MAPPING__', $properties, $code); + file_put_contents($modelPath, $code); return 0; @@ -122,6 +130,13 @@ public function getIndex(): string { return "__INDEX__"; } + + public function getMapping(): array + { + return [ + __MAPPING__ + ]; + } }'; } }