update:class增加when方法
This commit is contained in:
parent
0dfe4fb5c6
commit
21c1df4f69
@ -97,4 +97,21 @@ class Classes
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* when
|
||||
*
|
||||
* @time 2020年11月19日
|
||||
* @param $condition
|
||||
* @param \Closure $closure
|
||||
* @return $this
|
||||
*/
|
||||
public function when($condition, \Closure $closure)
|
||||
{
|
||||
if ($condition) {
|
||||
$closure($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@ -83,11 +83,13 @@ class Model extends Factory
|
||||
(new Property('name'))->default($table)->docComment('// 表名')
|
||||
);
|
||||
|
||||
$class->addProperty(
|
||||
(new Property('field'))->default(
|
||||
(new Arr)->build(Db::getFields($table))
|
||||
)->docComment('// 数据库字段映射')
|
||||
);
|
||||
$class->when($this->hasTableExists($table), function ($class) use ($table){
|
||||
$class->addProperty(
|
||||
(new Property('field'))->default(
|
||||
(new Arr)->build(Db::getFields($table))
|
||||
))->docComment('// 数据库字段映射');
|
||||
});
|
||||
|
||||
})->getContent();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user