@@ -15,6 +15,8 @@ class Generator
1515
1616 protected $ auth ;
1717
18+ protected $ host ;
19+
1820 protected $ docs ;
1921
2022 protected $ uri ;
@@ -25,11 +27,12 @@ class Generator
2527
2628 protected $ action ;
2729
28- public function __construct ($ config , $ routeFilter = null , $ auth = null )
30+ public function __construct ($ config , $ routeFilter = null , $ auth = null , $ host = null )
2931 {
3032 $ this ->config = $ config ;
3133 $ this ->routeFilter = $ routeFilter ;
3234 $ this ->auth = $ auth ;
35+ $ this ->host = $ host ;
3336 }
3437
3538 public function generate ()
@@ -59,6 +62,8 @@ public function generate()
5962
6063 $ this ->generatePath ();
6164
65+ $ this ->addTags ($ route ->getAction ());
66+
6267 $ this ->addAuthParameters ($ route ->middleware ());
6368 }
6469 }
@@ -75,7 +80,7 @@ protected function getBaseInfo()
7580 'description ' => $ this ->config ['description ' ],
7681 'version ' => $ this ->config ['appVersion ' ],
7782 ],
78- 'host ' => $ this ->config ['host ' ],
83+ 'host ' => ! empty ( $ this -> host ) ? $ this -> host : $ this ->config ['host ' ],
7984 'basePath ' => $ this ->config ['basePath ' ],
8085 ];
8186
@@ -136,6 +141,7 @@ protected function generatePath()
136141
137142 $ this ->docs ['paths ' ][$ this ->uri ][$ this ->method ] = [
138143 'description ' => "$ methodDescription {$ this ->uri }" ,
144+ 'tags ' => [],
139145 'responses ' => [
140146 '200 ' => [
141147 'description ' => 'OK '
@@ -180,6 +186,23 @@ protected function getFormRules()
180186 }
181187 }
182188
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+
183206 protected function addAuthParameters ($ middlewares )
184207 {
185208 if (!empty ($ this ->auth )) {
0 commit comments