@@ -15,6 +15,8 @@ class Generator
15
15
16
16
protected $ auth ;
17
17
18
+ protected $ host ;
19
+
18
20
protected $ docs ;
19
21
20
22
protected $ uri ;
@@ -25,11 +27,12 @@ class Generator
25
27
26
28
protected $ action ;
27
29
28
- public function __construct ($ config , $ routeFilter = null , $ auth = null )
30
+ public function __construct ($ config , $ routeFilter = null , $ auth = null , $ host = null )
29
31
{
30
32
$ this ->config = $ config ;
31
33
$ this ->routeFilter = $ routeFilter ;
32
34
$ this ->auth = $ auth ;
35
+ $ this ->host = $ host ;
33
36
}
34
37
35
38
public function generate ()
@@ -59,6 +62,8 @@ public function generate()
59
62
60
63
$ this ->generatePath ();
61
64
65
+ $ this ->addTags ($ route ->getAction ());
66
+
62
67
$ this ->addAuthParameters ($ route ->middleware ());
63
68
}
64
69
}
@@ -75,7 +80,7 @@ protected function getBaseInfo()
75
80
'description ' => $ this ->config ['description ' ],
76
81
'version ' => $ this ->config ['appVersion ' ],
77
82
],
78
- 'host ' => $ this ->config ['host ' ],
83
+ 'host ' => ! empty ( $ this -> host ) ? $ this -> host : $ this ->config ['host ' ],
79
84
'basePath ' => $ this ->config ['basePath ' ],
80
85
];
81
86
@@ -136,6 +141,7 @@ protected function generatePath()
136
141
137
142
$ this ->docs ['paths ' ][$ this ->uri ][$ this ->method ] = [
138
143
'description ' => "$ methodDescription {$ this ->uri }" ,
144
+ 'tags ' => [],
139
145
'responses ' => [
140
146
'200 ' => [
141
147
'description ' => 'OK '
@@ -180,6 +186,23 @@ protected function getFormRules()
180
186
}
181
187
}
182
188
189
+ protected function addTags ($ controllerArray )
190
+ {
191
+ $ tagName = $ this ->getControllerName ($ controllerArray );
192
+ $ this ->docs ['paths ' ][$ this ->uri ][$ this ->method ]['tags ' ][] = $ tagName ;
193
+ }
194
+
195
+ protected function getControllerName ($ controllerArray )
196
+ {
197
+ $ namespaceReplaced = str_replace ($ controllerArray ['namespace ' ]. '\\' , '' , $ controllerArray ['controller ' ]);
198
+ $ actionNameReplaced = substr ($ namespaceReplaced , 0 , strpos ($ namespaceReplaced , '@ ' ));
199
+ $ controllerReplaced = str_replace ('Controller ' , '' , $ actionNameReplaced );
200
+ $ controllerNameArray = preg_split ('/(?=[A-Z])/ ' , $ controllerReplaced );
201
+ $ controllerName = trim (implode (' ' , $ controllerNameArray ));
202
+
203
+ return $ controllerName ;
204
+ }
205
+
183
206
protected function addAuthParameters ($ middlewares )
184
207
{
185
208
if (!empty ($ this ->auth )) {
0 commit comments