mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2026-06-08 04:48:10 +08:00
feat: 增加模型自动生成用于IDE提示的注释工具
This commit is contained in:
parent
ec768a6e2a
commit
f0a7cce4bf
@ -25,21 +25,34 @@
|
||||
"ext-gd": "*",
|
||||
"ext-json": "*",
|
||||
"ext-openssl": "*",
|
||||
"zoujingli/think-plugs-wuma": "*",
|
||||
"zoujingli/think-plugs-admin": "*",
|
||||
"zoujingli/think-plugs-worker": "*",
|
||||
"zoujingli/think-plugs-center": "*",
|
||||
"zoujingli/think-plugs-wechat": "*",
|
||||
"zoujingli/think-plugs-wemall": "*",
|
||||
"topthink/think-orm": "^4.0",
|
||||
"zoujingli/think-plugs-account": "*",
|
||||
"zoujingli/think-plugs-admin": "*",
|
||||
"zoujingli/think-plugs-center": "*",
|
||||
"zoujingli/think-plugs-payment": "*",
|
||||
"zoujingli/think-plugs-wechat-service": "*"
|
||||
"zoujingli/think-plugs-wechat": "*",
|
||||
"zoujingli/think-plugs-wechat-service": "*",
|
||||
"zoujingli/think-plugs-wemall": "*",
|
||||
"zoujingli/think-plugs-worker": "*",
|
||||
"zoujingli/think-plugs-wuma": "*"
|
||||
},
|
||||
"require-dev": {
|
||||
"zoujingli/think-plugs-helper": "*"
|
||||
},
|
||||
"scripts": {
|
||||
"test": [
|
||||
"php -m"
|
||||
]
|
||||
},
|
||||
"repositories": [
|
||||
{
|
||||
"type": "path",
|
||||
"url": "plugin/think-plugs-wuma"
|
||||
},
|
||||
{
|
||||
"type": "path",
|
||||
"url": "plugin/think-plugs-helper"
|
||||
},
|
||||
{
|
||||
"type": "path",
|
||||
"url": "plugin/think-plugs-worker"
|
||||
|
||||
@ -154,7 +154,7 @@ class ToolsExtend
|
||||
* @param integer $currDepth 当前深度,临时变量递归时使用。
|
||||
* @return \Generator 返回 SplFileInfo 对象的生成器。
|
||||
*/
|
||||
private static function findFilesYield(string $path, ?int $depth = null, ?Closure $filter = null, bool $appendPath = false, int $currDepth = 1): Generator
|
||||
public static function findFilesYield(string $path, ?int $depth = null, ?Closure $filter = null, bool $appendPath = false, int $currDepth = 1): Generator
|
||||
{
|
||||
if (file_exists($path) && is_dir($path) && (is_null($depth) || $currDepth <= $depth)) {
|
||||
foreach (new FilesystemIterator($path, FilesystemIterator::SKIP_DOTS) as $item) {
|
||||
|
||||
29
plugin/think-plugs-helper/composer.json
Normal file
29
plugin/think-plugs-helper/composer.json
Normal file
@ -0,0 +1,29 @@
|
||||
{
|
||||
"type": "library",
|
||||
"name": "zoujingli/think-plugs-helper",
|
||||
"homepage": "https://thinkadmin.top",
|
||||
"description": "Developer Tools for ThinkAdmin",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Anyon",
|
||||
"email": "zoujingli@qq.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">7.1",
|
||||
"ext-json": "*",
|
||||
"topthink/think-ide-helper": "*"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"plugin\\helper\\": "src"
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"think": {
|
||||
"services": [
|
||||
"plugin\\helper\\Service"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
76
plugin/think-plugs-helper/src/ModelGen.php
Normal file
76
plugin/think-plugs-helper/src/ModelGen.php
Normal file
@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | Developer Tools for ThinkAdmin
|
||||
// +----------------------------------------------------------------------
|
||||
// | 版权所有 2014~2024 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 ModelGen 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;
|
||||
}
|
||||
}
|
||||
27
plugin/think-plugs-helper/src/Service.php
Normal file
27
plugin/think-plugs-helper/src/Service.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | Developer Tools for ThinkAdmin
|
||||
// +----------------------------------------------------------------------
|
||||
// | 版权所有 2014~2024 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;
|
||||
|
||||
class Service extends \think\Service
|
||||
{
|
||||
public function boot()
|
||||
{
|
||||
$this->commands([ModelGen::class]);
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user