@@ -32,28 +32,25 @@ class ExportPostmanCommand extends Command
32
32
/** @var null */
33
33
protected $ filename ;
34
34
35
+ /** @var string */
36
+ private $ bearer ;
37
+
35
38
public function __construct (Router $ router , Repository $ config )
36
39
{
37
40
parent ::__construct ();
38
41
39
42
$ this ->router = $ router ;
40
43
$ this ->config = $ config ['api-postman ' ];
41
- $ this ->filename = $ this ->formatFilename ();
42
44
}
43
45
44
46
public function handle (): void
45
47
{
46
- $ this ->initStructure ();
47
-
48
- if ($ bearer = $ this ->option ('bearer ' ) ?? false ) {
49
- $ this ->structure ['variable ' ][] = [
50
- 'key ' => 'token ' ,
51
- 'value ' => $ bearer ,
52
- ];
53
- }
48
+ $ this ->setFilename ();
49
+ $ this ->setBearerToken ();
50
+ $ this ->initializeStructure ();
54
51
55
52
foreach ($ this ->router ->getRoutes () as $ route ) {
56
- $ methods = collect ($ route ->methods ())-> reject ( fn ($ method ) => $ method == 'HEAD ' );
53
+ $ methods = array_filter ($ route ->methods (), fn ($ value ) => $ value ! == 'HEAD ' );
57
54
$ middlewares = $ route ->gatherMiddleware ();
58
55
59
56
foreach ($ methods as $ method ) {
@@ -103,7 +100,7 @@ public function handle(): void
103
100
104
101
$ routeHeaders = $ this ->config ['headers ' ];
105
102
106
- if ($ bearer && in_array ($ this ->config ['auth_middleware ' ], $ middlewares )) {
103
+ if ($ this -> bearer && in_array ($ this ->config ['auth_middleware ' ], $ middlewares )) {
107
104
$ routeHeaders [] = [
108
105
'key ' => 'Authorization ' ,
109
106
'value ' => 'Bearer {{token}} ' ,
@@ -229,7 +226,7 @@ public function makeRequest($route, $method, $routeHeaders, $requestRules)
229
226
return $ data ;
230
227
}
231
228
232
- protected function initStructure (): void
229
+ protected function initializeStructure (): void
233
230
{
234
231
$ this ->structure = [
235
232
'variable ' => [
@@ -244,17 +241,29 @@ protected function initStructure(): void
244
241
],
245
242
'item ' => [],
246
243
];
244
+
245
+ if ($ this ->bearer ) {
246
+ $ this ->structure ['variable ' ][] = [
247
+ 'key ' => 'token ' ,
248
+ 'value ' => $ this ->bearer ,
249
+ ];
250
+ }
247
251
}
248
252
249
- protected function formatFilename ()
253
+ protected function setFilename ()
250
254
{
251
- return str_replace (
255
+ $ this -> filename = str_replace (
252
256
['{timestamp} ' , '{app} ' ],
253
257
[date ('Y_m_d_His ' ), Str::snake (config ('app.name ' ))],
254
258
$ this ->config ['filename ' ]
255
259
);
256
260
}
257
261
262
+ protected function setBearerToken ()
263
+ {
264
+ $ this ->bearer = $ this ->option ('bearer ' ) ?? null ;
265
+ }
266
+
258
267
protected function isStructured ()
259
268
{
260
269
return $ this ->config ['structured ' ];
0 commit comments