diff --git a/composer.json b/composer.json index 555852903..bd7e076a9 100644 --- a/composer.json +++ b/composer.json @@ -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" diff --git a/plugin/think-library/src/extend/ToolsExtend.php b/plugin/think-library/src/extend/ToolsExtend.php index 5110fb0cd..ce10ee4cb 100644 --- a/plugin/think-library/src/extend/ToolsExtend.php +++ b/plugin/think-library/src/extend/ToolsExtend.php @@ -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) { diff --git a/plugin/think-plugs-helper/composer.json b/plugin/think-plugs-helper/composer.json new file mode 100644 index 000000000..4ac1ed020 --- /dev/null +++ b/plugin/think-plugs-helper/composer.json @@ -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" + ] + } + } +} diff --git a/plugin/think-plugs-helper/src/ModelGen.php b/plugin/think-plugs-helper/src/ModelGen.php new file mode 100644 index 000000000..ba8e4f6cd --- /dev/null +++ b/plugin/think-plugs-helper/src/ModelGen.php @@ -0,0 +1,76 @@ + +// +---------------------------------------------------------------------- +// | 官方网站: 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; + } +} \ No newline at end of file diff --git a/plugin/think-plugs-helper/src/Service.php b/plugin/think-plugs-helper/src/Service.php new file mode 100644 index 000000000..4a041e9d8 --- /dev/null +++ b/plugin/think-plugs-helper/src/Service.php @@ -0,0 +1,27 @@ + +// +---------------------------------------------------------------------- +// | 官方网站: 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]); + } +}