Skip to content

Commit 8fd7b9e

Browse files
committed
升级3.1.0
1 parent 7a82833 commit 8fd7b9e

File tree

6 files changed

+725
-2
lines changed

6 files changed

+725
-2
lines changed

src/Controller.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@ public function __construct(App $app)
5050
$defaultAppConfig = ['title'=>$default_app,'path'=>$path,'folder'=>$default_app];
5151
$config['apps'] = [$defaultAppConfig];
5252
}
53+
// 过滤关闭的生成器
54+
if (!empty($config['generator']) && count($config['generator'])){
55+
$generatorList =[];
56+
foreach ($config['generator'] as $item) {
57+
if (!isset($item['enable']) || (isset($item['enable']) && $item['enable']===true)){
58+
$generatorList[]=$item;
59+
}
60+
}
61+
$config['generator'] = $generatorList;
62+
}
5363

5464

5565
Config::set(['apidoc'=>$config]);
@@ -152,7 +162,6 @@ public function getApidoc(){
152162
// 获取默认控制器
153163
$default_app = $config = Config::get("app.default_app");
154164
$appKey = $default_app;
155-
156165
}
157166
$currentApps = (new Utils())->getCurrentApps($appKey);
158167
$currentApp = $currentApps[count($currentApps) - 1];
@@ -206,6 +215,16 @@ public function getMdMenus(){
206215
\think\facade\App::loadLangPack($params['lang']);
207216
}
208217
}
218+
if (!empty($params['appKey'])){
219+
// 获取指定应用
220+
$appKey = $params['appKey'];
221+
}else{
222+
// 获取默认控制器
223+
$default_app = $config = Config::get("app.default_app");
224+
$appKey = $default_app;
225+
}
226+
(new Auth())->checkAuth($appKey);
227+
209228
$docs = (new ParseMarkdown())->getDocsMenu($lang);
210229
return Utils::showJson(0,"",$docs);
211230

@@ -250,6 +269,14 @@ public function getMdDetail(){
250269
}
251270

252271

272+
public function createGenerator(){
273+
$request = Request::instance();
274+
$params = $request->param();
275+
$res = (new generator\Index())->create($params);
276+
return Utils::showJson(0,"",$res);
277+
}
278+
279+
253280

254281

255282

src/Service.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public function boot()
2121
Route::get('mdMenus' , $controller_namespace . 'getMdMenus');
2222
Route::get('mdDetail' , $controller_namespace . 'getMdDetail');
2323
Route::post('verifyAuth' , $controller_namespace . 'verifyAuth');
24+
Route::post('generator' , $controller_namespace . 'createGenerator');
2425
};
2526
if (!empty($apidocConfig['allowCrossDomain'])){
2627
Route::group($route_prefix, $routes)->allowCrossDomain();

src/Utils.php

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ public static function getArrayFind(array $array, $query)
224224
}
225225

226226
/**
227-
* 根据条件获取数组中的值
227+
* 根据条件获取数组中的index
228228
* @param array $array
229229
* @param $query
230230
* @return mixed|null
@@ -492,6 +492,38 @@ public static function arraySortByKey($array, $field="sort",$order=SORT_ASC){
492492
}
493493

494494

495+
/**
496+
* 格式化路径
497+
* @param $path
498+
* @param string $type
499+
* @return array|string|string[]
500+
*/
501+
public static function formatPath($path,$type="/"){
502+
if ($type==="/"){
503+
$path = str_replace("\\","/",$path);
504+
}else{
505+
$path = str_replace("/","\\",$path);
506+
$path = str_replace("\\\\","\\",$path);
507+
$endStr = substr($path, -1);
508+
if ($endStr=='\\'){
509+
$path = substr($path,0,strlen($path)-1);
510+
}
511+
}
512+
return $path;
513+
}
514+
515+
/**
516+
* 过滤所有空格换行符
517+
* @param $str
518+
* @return array|string|string[]
519+
*/
520+
public static function trimEmpty($str){
521+
$search = array(" "," ","\n","\r","\t");
522+
$replace = array("","","","","");
523+
return str_replace($search, $replace, $str);
524+
}
525+
526+
495527

496528

497529

src/exception/ErrorException.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ class ErrorException extends HttpException
2323
'no config crud' => ['code' => 5002, 'msg' => 'crud未配置'],
2424
'datatable crud error' => ['code' => 5003, 'msg' => '数据表创建失败,请检查配置'],
2525
'file already exists' => ['code' => 5004, 'msg' => '${filepath}文件已存在'],
26+
'file not exists' => ['code' => 5005, 'msg' => '${filepath}文件不存在'],
27+
'datatable already exists' => ['code' => 5004, 'msg' => '数据表${table}已存在'],
2628

2729
];
2830

0 commit comments

Comments
 (0)