|
@@ -76,7 +76,7 @@ discard block |
|
|
block discarded – undo |
|
76
|
76
|
|
|
77
|
77
|
$this->setUserToBeImpersonated($this->option('actAsUserId')); |
|
78
|
78
|
|
|
79
|
|
- if ($routePrefix === null && $routeDomain === null && ! count($allowedRoutes) && $middleware === null) { |
|
|
79
|
+ if ($routePrefix === null && $routeDomain === null && !count($allowedRoutes) && $middleware === null) { |
|
80
|
80
|
$this->error('You must provide either a route prefix, a route domain, a route or a middleware to generate the documentation.'); |
|
81
|
81
|
|
|
82
|
82
|
return false; |
|
@@ -94,7 +94,7 @@ discard block |
|
|
block discarded – undo |
|
94
|
94
|
$parsedRoutes += $this->processRoutes($generator, $allowedRoutes, $routeDomain, $routePrefix, $middleware); |
|
95
|
95
|
} |
|
96
|
96
|
} |
|
97
|
|
- $parsedRoutes = collect($parsedRoutes)->groupBy('resource')->sort(function ($a, $b) { |
|
|
97
|
+ $parsedRoutes = collect($parsedRoutes)->groupBy('resource')->sort(function($a, $b) { |
|
98
|
98
|
return strcmp($a->first()['resource'], $b->first()['resource']); |
|
99
|
99
|
}); |
|
100
|
100
|
|
|
@@ -109,17 +109,17 @@ discard block |
|
|
block discarded – undo |
|
109
|
109
|
private function writeMarkdown($parsedRoutes) |
|
110
|
110
|
{ |
|
111
|
111
|
$outputPath = $this->option('output'); |
|
112
|
|
- $targetFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'index.md'; |
|
113
|
|
- $compareFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'.compare.md'; |
|
114
|
|
- $prependFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'prepend.md'; |
|
115
|
|
- $appendFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'append.md'; |
|
|
112
|
+ $targetFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . 'index.md'; |
|
|
113
|
+ $compareFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . '.compare.md'; |
|
|
114
|
+ $prependFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . 'prepend.md'; |
|
|
115
|
+ $appendFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . 'append.md'; |
|
116
|
116
|
|
|
117
|
117
|
$infoText = view('apidoc::partials.info') |
|
118
|
118
|
->with('outputPath', ltrim($outputPath, 'public/')) |
|
119
|
|
- ->with('showPostmanCollectionButton', ! $this->option('noPostmanCollection')); |
|
|
119
|
+ ->with('showPostmanCollectionButton', !$this->option('noPostmanCollection')); |
|
120
|
120
|
|
|
121
|
|
- $parsedRouteOutput = $parsedRoutes->map(function ($routeGroup) { |
|
122
|
|
- return $routeGroup->map(function ($route) { |
|
|
121
|
+ $parsedRouteOutput = $parsedRoutes->map(function($routeGroup) { |
|
|
122
|
+ return $routeGroup->map(function($route) { |
|
123
|
123
|
$route['output'] = (string) view('apidoc::partials.route')->with('parsedRoute', $route)->render(); |
|
124
|
124
|
|
|
125
|
125
|
return $route; |
|
@@ -139,16 +139,16 @@ discard block |
|
|
block discarded – undo |
|
139
|
139
|
$frontmatter = trim($generatedFrontmatter[1], "\n"); |
|
140
|
140
|
} |
|
141
|
141
|
|
|
142
|
|
- $parsedRouteOutput->transform(function ($routeGroup) use ($generatedDocumentation, $compareDocumentation) { |
|
143
|
|
- return $routeGroup->transform(function ($route) use ($generatedDocumentation, $compareDocumentation) { |
|
144
|
|
- if (preg_match('/<!-- START_'.$route['id'].' -->(.*)<!-- END_'.$route['id'].' -->/is', $generatedDocumentation, $routeMatch)) { |
|
145
|
|
- $routeDocumentationChanged = (preg_match('/<!-- START_'.$route['id'].' -->(.*)<!-- END_'.$route['id'].' -->/is', $compareDocumentation, $compareMatch) && $compareMatch[1] !== $routeMatch[1]); |
|
|
142
|
+ $parsedRouteOutput->transform(function($routeGroup) use ($generatedDocumentation, $compareDocumentation) { |
|
|
143
|
+ return $routeGroup->transform(function($route) use ($generatedDocumentation, $compareDocumentation) { |
|
|
144
|
+ if (preg_match('/<!-- START_' . $route['id'] . ' -->(.*)<!-- END_' . $route['id'] . ' -->/is', $generatedDocumentation, $routeMatch)) { |
|
|
145
|
+ $routeDocumentationChanged = (preg_match('/<!-- START_' . $route['id'] . ' -->(.*)<!-- END_' . $route['id'] . ' -->/is', $compareDocumentation, $compareMatch) && $compareMatch[1] !== $routeMatch[1]); |
|
146
|
146
|
if ($routeDocumentationChanged === false || $this->option('force')) { |
|
147
|
147
|
if ($routeDocumentationChanged) { |
|
148
|
|
- $this->warn('Discarded manual changes for route ['.implode(',', $route['methods']).'] '.$route['uri']); |
|
|
148
|
+ $this->warn('Discarded manual changes for route [' . implode(',', $route['methods']) . '] ' . $route['uri']); |
|
149
|
149
|
} |
|
150
|
150
|
} else { |
|
151
|
|
- $this->warn('Skipping modified route ['.implode(',', $route['methods']).'] '.$route['uri']); |
|
|
151
|
+ $this->warn('Skipping modified route [' . implode(',', $route['methods']) . '] ' . $route['uri']); |
|
152
|
152
|
$route['modified_output'] = $routeMatch[0]; |
|
153
|
153
|
} |
|
154
|
154
|
} |
|
@@ -159,9 +159,9 @@ discard block |
|
|
block discarded – undo |
|
159
|
159
|
} |
|
160
|
160
|
|
|
161
|
161
|
$prependFileContents = file_exists($prependFile) |
|
162
|
|
- ? file_get_contents($prependFile)."\n" : ''; |
|
|
162
|
+ ? file_get_contents($prependFile) . "\n" : ''; |
|
163
|
163
|
$appendFileContents = file_exists($appendFile) |
|
164
|
|
- ? "\n".file_get_contents($appendFile) : ''; |
|
|
164
|
+ ? "\n" . file_get_contents($appendFile) : ''; |
|
165
|
165
|
|
|
166
|
166
|
$documentarian = new Documentarian(); |
|
167
|
167
|
|
|
@@ -172,10 +172,10 @@ discard block |
|
|
block discarded – undo |
|
172
|
172
|
->with('prependMd', $prependFileContents) |
|
173
|
173
|
->with('appendMd', $appendFileContents) |
|
174
|
174
|
->with('outputPath', $this->option('output')) |
|
175
|
|
- ->with('showPostmanCollectionButton', ! $this->option('noPostmanCollection')) |
|
|
175
|
+ ->with('showPostmanCollectionButton', !$this->option('noPostmanCollection')) |
|
176
|
176
|
->with('parsedRoutes', $parsedRouteOutput); |
|
177
|
177
|
|
|
178
|
|
- if (! is_dir($outputPath)) { |
|
|
178
|
+ if (!is_dir($outputPath)) { |
|
179
|
179
|
$documentarian->create($outputPath); |
|
180
|
180
|
} |
|
181
|
181
|
|
|
@@ -190,23 +190,23 @@ discard block |
|
|
block discarded – undo |
|
190
|
190
|
->with('prependMd', $prependFileContents) |
|
191
|
191
|
->with('appendMd', $appendFileContents) |
|
192
|
192
|
->with('outputPath', $this->option('output')) |
|
193
|
|
- ->with('showPostmanCollectionButton', ! $this->option('noPostmanCollection')) |
|
|
193
|
+ ->with('showPostmanCollectionButton', !$this->option('noPostmanCollection')) |
|
194
|
194
|
->with('parsedRoutes', $parsedRouteOutput); |
|
195
|
195
|
|
|
196
|
196
|
file_put_contents($compareFile, $compareMarkdown); |
|
197
|
197
|
|
|
198
|
|
- $this->info('Wrote index.md to: '.$outputPath); |
|
|
198
|
+ $this->info('Wrote index.md to: ' . $outputPath); |
|
199
|
199
|
|
|
200
|
200
|
$this->info('Generating API HTML code'); |
|
201
|
201
|
|
|
202
|
202
|
$documentarian->generate($outputPath); |
|
203
|
203
|
|
|
204
|
|
- $this->info('Wrote HTML documentation to: '.$outputPath.'/index.html'); |
|
|
204
|
+ $this->info('Wrote HTML documentation to: ' . $outputPath . '/index.html'); |
|
205
|
205
|
|
|
206
|
206
|
if ($this->option('noPostmanCollection') !== true) { |
|
207
|
207
|
$this->info('Generating Postman collection'); |
|
208
|
208
|
|
|
209
|
|
- file_put_contents($outputPath.DIRECTORY_SEPARATOR.'collection.json', $this->generatePostmanCollection($parsedRoutes)); |
|
|
209
|
+ file_put_contents($outputPath . DIRECTORY_SEPARATOR . 'collection.json', $this->generatePostmanCollection($parsedRoutes)); |
|
210
|
210
|
} |
|
211
|
211
|
} |
|
212
|
212
|
|
|
@@ -235,7 +235,7 @@ discard block |
|
|
block discarded – undo |
|
235
|
235
|
*/ |
|
236
|
236
|
private function setUserToBeImpersonated($actAs) |
|
237
|
237
|
{ |
|
238
|
|
- if (! empty($actAs)) { |
|
|
238
|
+ if (!empty($actAs)) { |
|
239
|
239
|
if (version_compare($this->laravel->version(), '5.2.0', '<')) { |
|
240
|
240
|
$userModel = config('auth.model'); |
|
241
|
241
|
$user = $userModel::find($actAs); |
|
@@ -284,9 +284,9 @@ discard block |
|
|
block discarded – undo |
|
284
|
284
|
) { |
|
285
|
285
|
if ($this->isValidRoute($route) && $this->isRouteVisibleForDocumentation($route->getAction()['uses'])) { |
|
286
|
286
|
$parsedRoutes[] = $generator->processRoute($route, $bindings, $this->option('header'), $withResponse && in_array('GET', $generator->getMethods($route))); |
|
287
|
|
- $this->info('Processed route: ['.implode(',', $generator->getMethods($route)).'] '.$generator->getUri($route)); |
|
|
287
|
+ $this->info('Processed route: [' . implode(',', $generator->getMethods($route)) . '] ' . $generator->getUri($route)); |
|
288
|
288
|
} else { |
|
289
|
|
- $this->warn('Skipping route: ['.implode(',', $generator->getMethods($route)).'] '.$generator->getUri($route)); |
|
|
289
|
+ $this->warn('Skipping route: [' . implode(',', $generator->getMethods($route)) . '] ' . $generator->getUri($route)); |
|
290
|
290
|
} |
|
291
|
291
|
} |
|
292
|
292
|
} |
|
@@ -301,7 +301,7 @@ discard block |
|
|
block discarded – undo |
|
301
|
301
|
*/ |
|
302
|
302
|
private function isValidRoute(Route $route) |
|
303
|
303
|
{ |
|
304
|
|
- return ! is_callable($route->getAction()['uses']) && ! is_null($route->getAction()['uses']); |
|
|
304
|
+ return !is_callable($route->getAction()['uses']) && !is_null($route->getAction()['uses']); |
|
305
|
305
|
} |
|
306
|
306
|
|
|
307
|
307
|
/** |
|
@@ -318,7 +318,7 @@ discard block |
|
|
block discarded – undo |
|
318
|
318
|
$phpdoc = new DocBlock($comment); |
|
319
|
319
|
|
|
320
|
320
|
return collect($phpdoc->getTags()) |
|
321
|
|
- ->filter(function ($tag) use ($route) { |
|
|
321
|
+ ->filter(function($tag) use ($route) { |
|
322
|
322
|
return $tag->getName() === 'hideFromAPIDocumentation'; |
|
323
|
323
|
}) |
|
324
|
324
|
->isEmpty(); |