update:class增加when方法
This commit is contained in:
parent
0dfe4fb5c6
commit
21c1df4f69
@ -97,4 +97,21 @@ class Classes
|
|||||||
|
|
||||||
return $this;
|
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('// 表名')
|
(new Property('name'))->default($table)->docComment('// 表名')
|
||||||
);
|
);
|
||||||
|
|
||||||
$class->addProperty(
|
$class->when($this->hasTableExists($table), function ($class) use ($table){
|
||||||
(new Property('field'))->default(
|
$class->addProperty(
|
||||||
(new Arr)->build(Db::getFields($table))
|
(new Property('field'))->default(
|
||||||
)->docComment('// 数据库字段映射')
|
(new Arr)->build(Db::getFields($table))
|
||||||
);
|
))->docComment('// 数据库字段映射');
|
||||||
|
});
|
||||||
|
|
||||||
})->getContent();
|
})->getContent();
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user