Skip to content

Commit f4df56d

Browse files
committed
修正问题
- 修正tp5.1获取md菜单多语言异常问题 - 修正自动生成url时继承类注解地址异常问题
1 parent a3d5085 commit f4df56d

File tree

4 files changed

+97
-97
lines changed

4 files changed

+97
-97
lines changed

README.md

Lines changed: 75 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,75 @@
1-
<p align="center">
2-
<img width="120" src="https://apidoc.demo.hg-code.com/images/logo.png">
3-
</p>
4-
5-
<h1 align="center">
6-
ThinkPHP ApiDoc
7-
</h1>
8-
9-
<div align="center">
10-
基于 ThinkPHP 的API接口开发工具
11-
</div>
12-
13-
<div align="center" style="margin-top:10px;margin-bottom:50px;">
14-
<a href="https://packagist.org/packages/hg/apidoc"><img src="https://img.shields.io/packagist/v/hg/apidoc"></a>
15-
<a href="https://packagist.org/packages/hg/apidoc"><img src="https://img.shields.io/packagist/dt/hg/apidoc"></a>
16-
<a href="https://packagist.org/packages/hg/apidoc"><img src="https://img.shields.io/packagist/l/hg/apidoc"></a>
17-
<a href="https://github.com/HGthecode/thinkphp-apidoc"><img src="https://img.shields.io/github/issues/HGthecode/thinkphp-apidoc"></a>
18-
<a href="https://github.com/HGthecode/thinkphp-apidoc"><img src="https://img.shields.io/github/forks/HGthecode/thinkphp-apidoc"></a>
19-
20-
</div>
21-
22-
23-
## 🤷‍♀️ Apidoc是什么?
24-
25-
如今,前后端分离的开发模式以必不可少,基于ThinkPHP可以很方便的作为Api接口的开发。可是一个Api开发过程中需要快速调试,开发完成后需要给其它开发者对接等,这时一个功能全面的Api文档工具,就显得特别重要。
26-
27-
大多数开发者可能都是通过各种工具配合来达到这一目的,其各种工具的安装和配置也是繁琐。甚至还有通过word等文本工具手写api文档的,这样的开发效率与可维护性是非常差的。
28-
29-
综合种种Api开发中的痛点,我们专为ThinkPHP开发了Apidoc的扩展,本插件可通过简单的注解即可生成Api文档,及帮助开发者提高生产效率的在线调试、快速生成Crud、一键生成整个模块Api等,涵盖Api开发方方面面。
30-
31-
32-
## ✨特性
33-
34-
- 开箱即用:无繁杂的配置、安装后按文档编写注释即可自动生成API文档。
35-
- 在线调试:在线文档可直接调试,支持全局参数、Mock调试数据、事件执行,接口调试省时省力。
36-
- 轻松使用:支持公共注释定义、业务逻辑层、数据表字段等引用,几句注释即可完成。
37-
- 安全高效:支持访问密码验证、应用/版本独立密码;支持文档缓存。
38-
- 多应用/多版本:可适应各种单应用、多应用、多版本的项目的Api管理。
39-
- Markdown文档:支持.md文件的文档展示。
40-
- 控制器分组:支持控制器多级分组,更精细化管理接口目录。
41-
- 多语言:可结合TP多语言能力,实现接口文档的语言切换。
42-
43-
44-
## 📌兼容
45-
46-
ThinkPHP 5.x
47-
48-
ThinkPHP 6.x
49-
50-
## 📖使用文档
51-
52-
[ThinkPHP ApiDoc V3.x文档](https://hg-code.gitee.io/thinkphp-apidoc/)
53-
54-
55-
## 🏆支持我们
56-
57-
如果本项目对您有所帮助,请点个Star支持我们
58-
59-
- [Github](https://github.com/HGthecode/thinkphp-apidoc) -> <a href="https://github.com/HGthecode/thinkphp-apidoc" target="_blank">
60-
<img height="22" src="https://img.shields.io/github/stars/HGthecode/thinkphp-apidoc?style=social" class="attachment-full size-full" alt="Star me on GitHub" data-recalc-dims="1" /></a>
61-
- [Gitee](https://gitee.com/hg-code/thinkphp-apidoc) -> <a href="https://gitee.com/hg-code/thinkphp-apidoc/stargazers"><img src="https://gitee.com/hg-code/thinkphp-apidoc/badge/star.svg" alt="star"></a>
62-
63-
## 💡鸣谢
64-
65-
<a href="http://www.thinkphp.cn/" target="_blank">ThinkPHP</a>
66-
67-
<a href="https://github.com/doctrine/annotations" target="_blank">doctrine/annotations</a>
68-
69-
70-
## 🔗链接
71-
<a href="https://github.com/HGthecode/apidoc-ui" target="_blank">ApiDoc UI</a>
72-
73-
<a href="https://github.com/HGthecode/thinkphp-apidoc-demo" target="_blank">ApiDoc Demo</a>
74-
75-
1+
<p align="center">
2+
<img width="120" src="https://apidoc.demo.hg-code.com/images/logo.png">
3+
</p>
4+
5+
<h1 align="center">
6+
ThinkPHP ApiDoc
7+
</h1>
8+
9+
<div align="center">
10+
基于 ThinkPHP 的API接口开发工具
11+
</div>
12+
13+
<div align="center" style="margin-top:10px;margin-bottom:50px;">
14+
<a href="https://packagist.org/packages/hg/apidoc"><img src="https://img.shields.io/packagist/v/hg/apidoc"></a>
15+
<a href="https://packagist.org/packages/hg/apidoc"><img src="https://img.shields.io/packagist/dt/hg/apidoc"></a>
16+
<a href="https://packagist.org/packages/hg/apidoc"><img src="https://img.shields.io/packagist/l/hg/apidoc"></a>
17+
<a href="https://github.com/HGthecode/thinkphp-apidoc"><img src="https://img.shields.io/github/issues/HGthecode/thinkphp-apidoc"></a>
18+
<a href="https://github.com/HGthecode/thinkphp-apidoc"><img src="https://img.shields.io/github/forks/HGthecode/thinkphp-apidoc"></a>
19+
20+
</div>
21+
22+
23+
## 🤷‍♀️ Apidoc是什么?
24+
25+
如今,前后端分离的开发模式以必不可少,基于ThinkPHP可以很方便的作为Api接口的开发。可是一个Api开发过程中需要快速调试,开发完成后需要给其它开发者对接等,这时一个功能全面的Api文档工具,就显得特别重要。
26+
27+
大多数开发者可能都是通过各种工具配合来达到这一目的,其各种工具的安装和配置也是繁琐。甚至还有通过word等文本工具手写api文档的,这样的开发效率与可维护性是非常差的。
28+
29+
综合种种Api开发中的痛点,我们专为ThinkPHP开发了Apidoc的扩展,本插件可通过简单的注解即可生成Api文档,及帮助开发者提高生产效率的在线调试、快速生成Crud、一键生成整个模块Api等,涵盖Api开发方方面面。
30+
31+
32+
## ✨特性
33+
34+
- 开箱即用:无繁杂的配置、安装后按文档编写注释即可自动生成API文档。
35+
- 在线调试:在线文档可直接调试,支持全局参数、Mock调试数据、事件执行,接口调试省时省力。
36+
- 轻松使用:支持公共注释定义、业务逻辑层、数据表字段等引用,几句注释即可完成。
37+
- 安全高效:支持访问密码验证、应用/版本独立密码;支持文档缓存。
38+
- 多应用/多版本:可适应各种单应用、多应用、多版本的项目的Api管理。
39+
- Markdown文档:支持.md文件的文档展示。
40+
- 控制器分组:支持控制器多级分组,更精细化管理接口目录。
41+
- 多语言:可结合TP多语言能力,实现接口文档的语言切换。
42+
43+
44+
## 📌兼容
45+
46+
ThinkPHP 5.1
47+
48+
ThinkPHP 6.x
49+
50+
## 📖使用文档
51+
52+
[ThinkPHP ApiDoc V3.x文档](https://hg-code.gitee.io/thinkphp-apidoc/)
53+
54+
55+
## 🏆支持我们
56+
57+
如果本项目对您有所帮助,请点个Star支持我们
58+
59+
- [Github](https://github.com/HGthecode/thinkphp-apidoc) -> <a href="https://github.com/HGthecode/thinkphp-apidoc" target="_blank">
60+
<img height="22" src="https://img.shields.io/github/stars/HGthecode/thinkphp-apidoc?style=social" class="attachment-full size-full" alt="Star me on GitHub" data-recalc-dims="1" /></a>
61+
- [Gitee](https://gitee.com/hg-code/thinkphp-apidoc) -> <a href="https://gitee.com/hg-code/thinkphp-apidoc/stargazers"><img src="https://gitee.com/hg-code/thinkphp-apidoc/badge/star.svg" alt="star"></a>
62+
63+
## 💡鸣谢
64+
65+
<a href="http://www.thinkphp.cn/" target="_blank">ThinkPHP</a>
66+
67+
<a href="https://github.com/doctrine/annotations" target="_blank">doctrine/annotations</a>
68+
69+
70+
## 🔗链接
71+
<a href="https://github.com/HGthecode/apidoc-ui" target="_blank">ApiDoc UI</a>
72+
73+
<a href="https://github.com/HGthecode/thinkphp-apidoc-demo" target="_blank">ApiDoc Demo</a>
74+
75+

src/Controller.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,16 +196,17 @@ public function getMdMenus(){
196196
// 获取md
197197
$request = Request::instance();
198198
$params = $request->param();
199-
199+
$lang = "";
200200
if (!empty($params['lang'])){
201+
$lang = $params['lang'];
201202
if ($this->tp_version === 5){
202203
Lang::setLangCookieVar($params['lang']);
203204
}else{
204205
Lang::setLangSet($params['lang']);
205206
\think\facade\App::loadLangPack($params['lang']);
206207
}
207208
}
208-
$docs = (new ParseMarkdown())->getDocsMenu();
209+
$docs = (new ParseMarkdown())->getDocsMenu($lang);
209210
return Utils::showJson(0,"",$docs);
210211

211212
}

src/parseApi/ParseAnnotation.php

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ protected function parseController($class)
207207

208208
foreach ($refClass->getMethods(\ReflectionMethod::IS_PUBLIC) as $refMethod) {
209209

210-
$methodItem = $this->parseApiMethod($refMethod,$routeGroup);
210+
$methodItem = $this->parseApiMethod($refClass,$refMethod,$routeGroup);
211211
if ($methodItem===false){
212212
continue;
213213
}
@@ -222,7 +222,7 @@ protected function parseController($class)
222222
}
223223

224224

225-
protected function parseApiMethod($refMethod,$routeGroup){
225+
protected function parseApiMethod($refClass,$refMethod,$routeGroup){
226226
$config = $this->config;
227227
if (empty($refMethod->name)) {
228228
return false;
@@ -356,10 +356,9 @@ protected function parseApiMethod($refMethod,$routeGroup){
356356
}
357357
}
358358
}
359-
360359
// 无url,自动生成
361360
if (empty($methodItem['url'])) {
362-
$methodItem['url'] = $this->autoCreateUrl($refMethod);
361+
$methodItem['url'] = $this->autoCreateUrl($refClass->name,$refMethod);
363362
} else if (!empty($routeGroup->value)) {
364363
// 路由分组,url加上分组
365364
$methodItem['url'] = '/' . $routeGroup->value . '/' . $methodItem['url'];
@@ -376,18 +375,18 @@ protected function parseApiMethod($refMethod,$routeGroup){
376375
* @param $method
377376
* @return string
378377
*/
379-
protected function autoCreateUrl($method): string
378+
protected function autoCreateUrl($classPath,$method): string
380379
{
381380
if (!empty($this->config['auto_url']) && !empty($this->config['auto_url']['custom']) && is_callable($this->config['auto_url']['custom'])){
382-
return $this->config['auto_url']['custom']($method->class,$method->name);
381+
return $this->config['auto_url']['custom']($classPath,$method->name);
383382
}
384383
$searchString = $this->controller_layer . '\\';
385-
$substr = substr(strstr($method->class, $searchString), strlen($searchString));
384+
$substr = substr(strstr($classPath, $searchString), strlen($searchString));
386385
$multistage_route_separator = ".";
387386
if (!empty($this->config['auto_url']) && !empty($this->config['auto_url']['multistage_route_separator'])){
388387
$multistage_route_separator = $this->config['auto_url']['multistage_route_separator'];
389388
}
390-
$pathArr = explode("\\", str_replace($substr, str_replace('\\', $multistage_route_separator, $substr), $method->class));
389+
$pathArr = explode("\\", str_replace($substr, str_replace('\\', $multistage_route_separator, $substr), $classPath));
391390
$filterPathNames = array($this->controller_layer);
392391
$appNameespace = App::getNamespace();
393392
if (strpos($appNameespace, '\\') !== false){
@@ -396,27 +395,27 @@ protected function autoCreateUrl($method): string
396395
}else{
397396
$filterPathNames[]=App::getNamespace();
398397
}
399-
$classPathArr = [];
398+
$classUrlArr = [];
400399
foreach ($pathArr as $item) {
401400
if (!in_array($item, $filterPathNames)) {
402401
if (!empty($this->config['auto_url']) && !empty($this->config['auto_url']['letter_rule'])){
403402
switch ($this->config['auto_url']['letter_rule']) {
404403
case 'lcfirst':
405-
$classPathArr[] = lcfirst($item);
404+
$classUrlArr[] = lcfirst($item);
406405
break;
407406
case 'ucfirst':
408-
$classPathArr[] = ucfirst($item);
407+
$classUrlArr[] = ucfirst($item);
409408
break;
410409
default:
411-
$classPathArr[] = $item;
410+
$classUrlArr[] = $item;
412411
}
413412
}else{
414-
$classPathArr[] = $item;
413+
$classUrlArr[] = $item;
415414
}
416415
}
417416
}
418-
$classPath = implode('/', $classPathArr);
419-
return '/' . $classPath . '/' . $method->name;
417+
$classUrl = implode('/', $classUrlArr);
418+
return '/' . $classUrl . '/' . $method->name;
420419
}
421420

422421
/**

src/parseApi/ParseMarkdown.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ public function __construct()
2121
* 获取md文档菜单
2222
* @return array
2323
*/
24-
public function getDocsMenu(): array
24+
public function getDocsMenu(string $lang): array
2525
{
2626
$config = $this->config;
2727
$docData = [];
2828
if (!empty($config['docs']) && count($config['docs']) > 0) {
29-
$docData = $this->handleDocsMenuData($config['docs']);
29+
$docData = $this->handleDocsMenuData($config['docs'],$lang);
3030
}
3131
return $docData;
3232
}
@@ -36,17 +36,17 @@ public function getDocsMenu(): array
3636
* @param array $menus
3737
* @return array
3838
*/
39-
protected function handleDocsMenuData(array $menus): array
39+
protected function handleDocsMenuData(array $menus,string $lang): array
4040
{
4141
$list = [];
4242
foreach ($menus as $item) {
4343
$item['title'] = Utils::getLang($item['title']);
4444
if(!empty($item['path'])){
45-
$lang = Lang::getLangSet();
45+
// $lang = Lang::getLangSet();
4646
$item['path'] = Utils::replaceTemplate($item['path'],['lang'=>$lang]);
4747
}
4848
if (!empty($item['children']) && count($item['children']) > 0) {
49-
$item['children'] = $this->handleDocsMenuData($item['children']);
49+
$item['children'] = $this->handleDocsMenuData($item['children'],$lang);
5050
$item['menu_key'] = Utils::createRandKey("md_group");
5151
} else {
5252
$item['type'] = 'md';

0 commit comments

Comments
 (0)