Skip to content

Commit c8fac1a

Browse files
committed
更新3.0.4
1 parent 832b4ce commit c8fac1a

File tree

5 files changed

+96
-89
lines changed

5 files changed

+96
-89
lines changed

src/Utils.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,12 @@ public function handleAppsConfig(array $apps,$isHandlePassword=false):array
364364
if (!empty($app['groups']) && count($app['groups']) > 0){
365365
$app['groups'] = $this->handleGroupsConfig($app['groups']);
366366
}
367+
if (!empty($app['headers']) && count($app['headers']) > 0){
368+
$app['headers'] = Utils::getArrayLang($app['headers'],"desc");
369+
}
370+
if (!empty($app['parameters']) && count($app['parameters']) > 0){
371+
$app['parameters'] = Utils::getArrayLang($app['parameters'],"desc");
372+
}
367373
$appsConfig[] = $app;
368374
}
369375
return $appsConfig;

src/annotation/After.php

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,10 @@
1111
* @Annotation
1212
* @Target({"METHOD","ANNOTATION"})
1313
*/
14-
final class After extends Annotation
14+
final class After extends EventBase
1515
{
1616

17-
/**
18-
* key
19-
* @var string
20-
*/
21-
public $key;
17+
2218

2319
/**
2420
* 事件
@@ -27,36 +23,7 @@ final class After extends Annotation
2723
*/
2824
public $event;
2925

30-
/**
31-
* ajax时的url
32-
* @var string
33-
*/
34-
public $url;
35-
36-
/**
37-
* ajax时的Method
38-
* @Enum({"GET", "POST", "PUT", "DELETE"})
39-
* @var string
40-
*/
41-
public $method;
42-
43-
/**
44-
* ajax时的 content-type
45-
* @var string
46-
*/
47-
public $contentType;
4826

49-
/**
50-
* 描述
51-
* @var string
52-
*/
53-
public $desc;
54-
55-
/**
56-
* 引用
57-
* @var string
58-
*/
59-
public $ref;
6027

6128

6229
}

src/annotation/Before.php

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -11,51 +11,13 @@
1111
* @Annotation
1212
* @Target({"METHOD","ANNOTATION"})
1313
*/
14-
final class Before extends Annotation
14+
final class Before extends EventBase
1515
{
16-
17-
/**
18-
* key
19-
* @var string
20-
*/
21-
public $key;
22-
2316
/**
2417
* 事件
2518
* @Enum({"setHeader", "setGlobalHeader", "setParam", "setGlobalParam", "clearGlobalHeader", "clearGlobalParam", "clearParam","handleParam",""})
2619
* @var string
2720
*/
2821
public $event;
2922

30-
/**
31-
* ajax时的url
32-
* @var string
33-
*/
34-
public $url;
35-
36-
/**
37-
* ajax时的Method
38-
* @Enum({"GET", "POST", "PUT", "DELETE"})
39-
* @var string
40-
*/
41-
public $method;
42-
43-
/**
44-
* ajax时的 content-type
45-
* @var string
46-
*/
47-
public $contentType;
48-
49-
/**
50-
* 描述
51-
* @var string
52-
*/
53-
public $desc;
54-
55-
/**
56-
* 引用
57-
* @var string
58-
*/
59-
public $ref;
60-
6123
}

src/annotation/EventBase.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
namespace hg\apidoc\annotation;
4+
5+
use Doctrine\Common\Annotations\Annotation;
6+
7+
abstract class EventBase extends Annotation
8+
{
9+
10+
/**
11+
* key
12+
* @var string
13+
*/
14+
public $key;
15+
16+
17+
18+
/**
19+
* ajax时的url
20+
* @var string
21+
*/
22+
public $url;
23+
24+
/**
25+
* ajax时的Method
26+
* @Enum({"GET", "POST", "PUT", "DELETE"})
27+
* @var string
28+
*/
29+
public $method;
30+
31+
/**
32+
* ajax时的 content-type
33+
* @var string
34+
*/
35+
public $contentType;
36+
37+
/**
38+
* 描述
39+
* @var string
40+
*/
41+
public $desc;
42+
43+
/**
44+
* 引用
45+
* @var string
46+
*/
47+
public $ref;
48+
49+
/**
50+
* 设置全局参数setGlobalHeader、setGlobalParam时指定应用
51+
* @var string
52+
*/
53+
public $appKey;
54+
55+
56+
57+
}

src/parseApi/ParseAnnotation.php

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ class ParseAnnotation
4343

4444
protected $controller_layer = "";
4545

46+
protected $currentApp = [];
47+
4648
public function __construct()
4749
{
4850
$this->reader = new AnnotationReader();
@@ -59,6 +61,7 @@ public function renderApiData(string $appKey): array
5961
{
6062
$currentApps = (new Utils())->getCurrentApps($appKey);
6163
$currentApp = $currentApps[count($currentApps) - 1];
64+
$this->currentApp = $currentApp;
6265

6366
if (!empty($currentApp['controllers']) && count($currentApp['controllers']) > 0) {
6467
// 配置的控制器列表
@@ -236,30 +239,39 @@ protected function parseApiMethod($refMethod,$routeGroup){
236239
$methodItem['title'] = Utils::getLang($textAnnotations[0]);
237240
}
238241
// 添加统一headers请求头参数
239-
if (!empty($config['headers']) && !in_array("NotHeaders", $textAnnotations)) {
240-
$configHeaders = [];
241-
foreach ($config['headers'] as $headerItem){
242+
if ((!empty($config['headers']) || !empty($this->currentApp['headers'])) && !in_array("NotHeaders", $textAnnotations)) {
243+
$headers = [];
244+
$configHeaders = !empty($config['headers'])?$config['headers']:[];
245+
if (!empty($this->currentApp['headers'])){
246+
$configHeaders = Utils::arrayMergeAndUnique("name", $configHeaders, $this->currentApp['headers']);
247+
}
248+
foreach ($configHeaders as $headerItem){
242249
$headerItem['desc'] = Utils::getLang($headerItem['desc']);
243-
$configHeaders[] = $headerItem;
250+
$headers[] = $headerItem;
244251
}
245252
if (!empty($methodItem['header'])) {
246-
$methodItem['header'] = Utils::arrayMergeAndUnique("name", $configHeaders, $methodItem['header']);
253+
$methodItem['header'] = Utils::arrayMergeAndUnique("name", $headers, $methodItem['header']);
247254
} else {
248-
$methodItem['header'] = $configHeaders;
255+
$methodItem['header'] = $headers;
249256
}
250257
}
258+
251259
// 添加统一params请求参数
252-
if (!empty($config['parameters']) && !in_array("NotParameters", $textAnnotations)) {
253-
$configParams = [];
254-
foreach ($config['parameters'] as $paramItem){
260+
if ((!empty($config['parameters']) || !empty($this->currentApp['parameters'])) && !in_array("NotParameters", $textAnnotations)) {
261+
$params = [];
262+
$configParams = !empty($config['parameters'])?$config['parameters']:[];
263+
if (!empty($this->currentApp['parameters'])){
264+
$configParams = Utils::arrayMergeAndUnique("name", $configParams, $this->currentApp['parameters']);
265+
}
266+
foreach ($configParams as $paramItem){
255267
$paramItem['desc'] = Utils::getLang($paramItem['desc']);
256-
$configParams[] = $paramItem;
268+
$params[] = $paramItem;
257269
}
258270

259271
if (!empty($methodItem['param'])) {
260272
$methodItem['param'] = Utils::arrayMergeAndUnique("name", $configParams, $methodItem['param']);
261273
} else {
262-
$methodItem['param'] = $configParams;
274+
$methodItem['param'] = $params;
263275
}
264276
}
265277
// 添加responses统一响应体
@@ -323,17 +335,20 @@ protected function parseApiMethod($refMethod,$routeGroup){
323335

324336
// Tags
325337
if (!empty($methodItem['tag'])) {
326-
$tagText = Utils::getLang($methodItem['tag']);
338+
$tagText = $methodItem['tag'];
327339
if (strpos($tagText, ',') !== false) {
328340
$tagArr = explode(",", $tagText);
341+
$tagList = [];
329342
foreach ($tagArr as $tag) {
343+
$t = Utils::getLang($tag);
344+
$tagList[]=$t;
330345
if (!in_array($tag, $this->tags)) {
331-
$this->tags[] = $tag;
346+
$this->tags[] = $t;
332347
}
333348
}
334-
$methodItem['tag'] = $tagArr;
349+
$methodItem['tag'] = $tagList;
335350
} else {
336-
$methodItem['tag'] = [$tagText];
351+
$methodItem['tag'] = [Utils::getLang($tagText)];
337352
if (!in_array($tagText, $this->tags)) {
338353
$this->tags[] = $tagText;
339354
}

0 commit comments

Comments
 (0)