From b91e6ba864bdcc0be502107f61842315986c4f4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=93=AD=E6=98=95?= <715557344@qq.com> Date: Sun, 30 Jun 2024 21:55:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E7=94=9F=E6=88=90=20Mapping?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Command/GenCommand.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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__ + ]; + } }'; } }