mirror of
https://gitee.com/apiadmin/ApiAdmin.git
synced 2025-04-05 05:42:45 +08:00
modified 初始化自动构建
This commit is contained in:
parent
792c743fd7
commit
49997cad87
97
app/command/AutoBuildFile.php
Normal file
97
app/command/AutoBuildFile.php
Normal file
@ -0,0 +1,97 @@
|
||||
<?php
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\command;
|
||||
|
||||
use app\util\AutoBuild;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
|
||||
class AutoBuildFile extends Command {
|
||||
protected function configure() {
|
||||
// 指令配置
|
||||
$this->setName('apiadmin:autoBuild')->setDescription('ApiAdmin自动构建文件');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output): void {
|
||||
$config = $this->parseConfig($output);
|
||||
(new AutoBuild())->run($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取cli配置输入
|
||||
* @param $output
|
||||
* @return array
|
||||
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||
*/
|
||||
private function parseConfig($output): array {
|
||||
$output->comment('Do you need to build a control? 1 or 0 (default 1)');
|
||||
$input = trim(fgets(fopen('php://stdin', 'r')));
|
||||
$dsn['control'] = strlen($input) ? $input : 1;
|
||||
|
||||
if ($dsn['control']) {
|
||||
$dsn['name'] = $this->getControlName($output);
|
||||
}
|
||||
|
||||
$output->comment('Do you need to build a menu? 1 or 0 (default 1):');
|
||||
$input = trim(fgets(fopen('php://stdin', 'r')));
|
||||
$dsn['menu'] = strlen($input) ? $input : 1;
|
||||
|
||||
if ($dsn['menu']) {
|
||||
$output->comment('Do you need to create a route? 1 or 0 (default 0):');
|
||||
$input = trim(fgets(fopen('php://stdin', 'r')));
|
||||
$dsn['route'] = strlen($input) ? $input : 0;
|
||||
}
|
||||
|
||||
$output->comment('Do you need to build a model? 1 or 0 (default 0):');
|
||||
$input = trim(fgets(fopen('php://stdin', 'r')));
|
||||
$dsn['model'] = strlen($input) ? $input : 0;
|
||||
|
||||
if ($dsn['model']) {
|
||||
$dsn['modelName'] = $this->getModelName($output);
|
||||
|
||||
$output->comment('Do you need to create a table? 1 or 0 (default 0):');
|
||||
$input = trim(fgets(fopen('php://stdin', 'r')));
|
||||
$dsn['table'] = strlen($input) ? $input : 0;
|
||||
}
|
||||
|
||||
$output->comment('please choose module (1:admin;2:api, default 1):');
|
||||
$input = trim(fgets(fopen('php://stdin', 'r')));
|
||||
$dsn['module'] = strlen($input) ? $input : 1;
|
||||
|
||||
return $dsn;
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归获取控制器名称
|
||||
* @param $output
|
||||
* @return string
|
||||
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||
*/
|
||||
private function getModelName($output): string {
|
||||
$output->comment('Please input model name');
|
||||
$input = trim(fgets(fopen('php://stdin', 'r')));
|
||||
if ($input) {
|
||||
return $input;
|
||||
} else {
|
||||
return $this->getModelName($output);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归获取控制器名称
|
||||
* @param $output
|
||||
* @return string
|
||||
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||
*/
|
||||
private function getControlName($output): string {
|
||||
$output->comment('Please input controller name');
|
||||
$input = trim(fgets(fopen('php://stdin', 'r')));
|
||||
if ($input) {
|
||||
return $input;
|
||||
} else {
|
||||
return $this->getControlName($output);
|
||||
}
|
||||
}
|
||||
}
|
@ -85,9 +85,8 @@ class Install extends Command {
|
||||
* @param $output
|
||||
* @return array
|
||||
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||
* @desc mysql://root:123456@127.0.0.1:3306/apiadmin#utf8mb4
|
||||
*/
|
||||
private function parseDsnConfig($output) {
|
||||
private function parseDsnConfig($output): array {
|
||||
$output->comment('please input database type(default mysql):');
|
||||
$input = trim(fgets(fopen('php://stdin', 'r')));
|
||||
$dsn['type'] = $input ? $input : 'mysql';
|
||||
|
@ -11,17 +11,30 @@ namespace app\util;
|
||||
class AutoBuild {
|
||||
|
||||
private $config = [
|
||||
'model' => 0, // 是否需要构建模型
|
||||
'control' => 1, // 是否需要构建控制器
|
||||
'menu' => 1, // 是否需要构建目录
|
||||
'route' => 1, // 是否需要构建路由
|
||||
'name' => '', // 唯一标识
|
||||
'module' => 1, // 构建类型 1:admin;2:api
|
||||
'table' => '' // 表名称
|
||||
'model' => 0, // 是否需要构建模型
|
||||
'control' => 1, // 是否需要构建控制器
|
||||
'menu' => 1, // 是否需要构建目录
|
||||
'route' => 1, // 是否需要构建路由
|
||||
'name' => '', // 唯一标识
|
||||
'module' => 1, // 构建类型 1:admin;2:api
|
||||
'table' => 0, // 是否创建表
|
||||
'modelName' => '' // 表名称
|
||||
];
|
||||
|
||||
public function run($config) {
|
||||
public function run($config = []) {
|
||||
$config = array_merge($this->config, $config);
|
||||
dump($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* 驼峰命名转下划线命名
|
||||
* @param $camelCaps
|
||||
* @param string $separator
|
||||
* @return string
|
||||
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||
*/
|
||||
private function unCamelize($camelCaps, $separator = '_'): string {
|
||||
return strtolower(preg_replace('/([a-z])([A-Z])/', "$1" . $separator . "$2", $camelCaps));
|
||||
}
|
||||
|
||||
private function buildControl() {
|
||||
|
@ -7,6 +7,7 @@ return [
|
||||
'commands' => [
|
||||
'apiadmin:adminRouter' => 'app\command\FreshAdminRouter',
|
||||
'apiadmin:install' => 'app\command\Install',
|
||||
'apiadmin:test' => 'app\command\ApiAdmin'
|
||||
'apiadmin:test' => 'app\command\ApiAdmin',
|
||||
'apiadmin:autoBuild' => 'app\command\AutoBuildFile'
|
||||
],
|
||||
];
|
||||
|
Loading…
x
Reference in New Issue
Block a user