邹景立 acb2b05c26 fix: 进一步完善数据库同步工具包
fix: 修正代码注释

This reverts commit 373427a539459a7abe17479e89ed9d9d353fff67.
2025-08-17 22:20:59 +08:00

76 lines
2.9 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
// +----------------------------------------------------------------------
// | Developer Tools for ThinkAdmin
// +----------------------------------------------------------------------
// | 版权所有 2014~2025 Anyon <zoujingli@qq.com>
// +----------------------------------------------------------------------
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免责声明 ( https://thinkadmin.top/disclaimer )
// +----------------------------------------------------------------------
// | gitee 代码仓库https://gitee.com/zoujingli/think-plugs-helper
// | github 代码仓库https://github.com/zoujingli/think-plugs-helper
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace plugin\helper;
use Ergebnis\Classy\Constructs;
use SplFileInfo;
use think\admin\extend\ToolsExtend;
use think\console\input\Argument;
use think\console\input\Option;
use think\ide\console\ModelCommand;
/**
* 创建模型注释
* @class ModelGen
* @package plugin\helper
*/
class DbModelStruct extends ModelCommand
{
protected function configure()
{
$this->setName("xadmin:helper:model")
->addArgument('model', Argument::OPTIONAL | Argument::IS_ARRAY, 'Which models to include', [])
->addOption('dir', 'D', Option::VALUE_OPTIONAL | Option::VALUE_IS_ARRAY, 'The model dir', [])
->addOption('ignore', 'I', Option::VALUE_OPTIONAL, 'Which models to ignore', '')
->addOption('reset', 'R', Option::VALUE_NONE, 'Remove the original phpdocs instead of appending')
->addOption('overwrite', 'O', Option::VALUE_NONE, 'Overwrite the phpdocs');
$this->setDescription("自动生成用于IDE提示的模型注释");
}
public function handle()
{
$this->dirs = array_merge(['app', 'plugin'], $this->input->getOption('dir'));
$model = $this->input->getArgument('model');
$ignore = $this->input->getOption('ignore');
$this->overwrite = $this->input->getOption('overwrite');
$this->reset = $this->input->getOption('reset');
$this->generateDocs($model, $ignore);
}
protected function loadModels(): array
{
$models = [];
foreach ($this->dirs as $dir) {
iterator_to_array(ToolsExtend::findFilesYield($this->app->getRootPath() . $dir, null, function (SplFileInfo $info) use (&$models) {
if ($info->isDir() && $info->getFilename() === 'model') {
foreach (Constructs::fromDirectory($info->getRealPath()) as $construct) {
$models[] = $construct->name();
}
return false;
}
return true;
}));
}
return $models;
}
}