|
@@ -55,7 +55,12 @@ class GenerateModelAnnotation extends Command
|
|
|
public function handle()
|
|
public function handle()
|
|
|
{
|
|
{
|
|
|
// 扫描核心模型目录
|
|
// 扫描核心模型目录
|
|
|
- $this->call1(app_path('../UCore'), '\UCore\Models\\');
|
|
|
|
|
|
|
+ $ucoreModelsDir = app_path('../UCore/Models');
|
|
|
|
|
+ if (is_dir($ucoreModelsDir)) {
|
|
|
|
|
+ $this->call1($ucoreModelsDir, '\UCore\Models\\');
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $this->warn("UCore Models 目录不存在: $ucoreModelsDir");
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
// 扫描模块下的Models目录
|
|
// 扫描模块下的Models目录
|
|
|
$modulesPath = app_path('Module');
|
|
$modulesPath = app_path('Module');
|
|
@@ -128,10 +133,35 @@ class GenerateModelAnnotation extends Command
|
|
|
public function call2($model,$modelClass,$file)
|
|
public function call2($model,$modelClass,$file)
|
|
|
{
|
|
{
|
|
|
if(class_exists($modelClass)){
|
|
if(class_exists($modelClass)){
|
|
|
|
|
+ // 检查类是否是抽象类
|
|
|
|
|
+ $reflectionClass = new \ReflectionClass($modelClass);
|
|
|
|
|
+ if ($reflectionClass->isAbstract()) {
|
|
|
|
|
+ $this->output->warning(" model $modelClass 是抽象类,跳过");
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 检查类是否是模型类
|
|
|
|
|
+ if (!$reflectionClass->isSubclassOf(\Illuminate\Database\Eloquent\Model::class)) {
|
|
|
|
|
+ $this->output->warning(" model $modelClass 不是模型类,跳过");
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 检查构造函数是否需要参数
|
|
|
|
|
+ $constructor = $reflectionClass->getConstructor();
|
|
|
|
|
+ if ($constructor && $constructor->getNumberOfRequiredParameters() > 0) {
|
|
|
|
|
+ $this->output->warning(" model $modelClass 需要构造函数参数,跳过");
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* @var ModelCore $model
|
|
* @var ModelCore $model
|
|
|
*/
|
|
*/
|
|
|
- $model = new $modelClass();
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ $model = new $modelClass();
|
|
|
|
|
+ } catch (\Throwable $e) {
|
|
|
|
|
+ $this->output->error(" model $modelClass 实例化失败: " . $e->getMessage());
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
if($model instanceof Model){
|
|
if($model instanceof Model){
|
|
|
$co = $model->getConnection();
|
|
$co = $model->getConnection();
|
|
|
$tTablePrefix = $co->getTablePrefix();
|
|
$tTablePrefix = $co->getTablePrefix();
|