模型生成新增字段属性注释
This commit is contained in:
parent
41aa81069c
commit
58286b181b
@ -11,7 +11,6 @@ use catcher\generate\factory\SQL;
|
||||
use catcher\generate\support\Table;
|
||||
use catcher\library\Composer;
|
||||
use catcher\Utils;
|
||||
use think\facade\Db;
|
||||
|
||||
class Generator
|
||||
{
|
||||
@ -45,7 +44,6 @@ class Generator
|
||||
|
||||
$files = [];
|
||||
$migration = '';
|
||||
$table = null;
|
||||
|
||||
try {
|
||||
if ($params['create_controller']) {
|
||||
|
@ -72,7 +72,9 @@ class Model extends Factory
|
||||
$build->use((new Uses())->name(BaseOptionsTrait::class));
|
||||
$build->use((new Uses())->name(ScopeTrait::class));
|
||||
})
|
||||
->class((new Classes($modelName))->extend('Model')->docComment(),
|
||||
->class((new Classes($modelName))
|
||||
->extend('Model')
|
||||
->docComment($this->buildClassComment($table)),
|
||||
function (Classes $class) use ($softDelete, $table) {
|
||||
if (!$softDelete) {
|
||||
$class->addTrait(
|
||||
@ -94,4 +96,26 @@ class Model extends Factory
|
||||
});
|
||||
})->getContent();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 提供模型字段属性提示
|
||||
*
|
||||
* @time 2021年04月27日
|
||||
* @param $table
|
||||
* @return string
|
||||
*/
|
||||
protected function buildClassComment($table): string
|
||||
{
|
||||
$fields = Db::name($table)->getFieldsType();
|
||||
|
||||
$comment = '/**' . PHP_EOL . ' *' . PHP_EOL;
|
||||
|
||||
foreach ($fields as $field => $type) {
|
||||
$comment .= sprintf(' * @property %s $%s', $type, $field) . PHP_EOL;
|
||||
}
|
||||
|
||||
$comment .= ' */';
|
||||
|
||||
return $comment;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user