|
@@ -83,7 +83,7 @@ discard block |
|
|
block discarded – undo |
|
83
|
83
|
$generator = new Generator($this->docConfig); |
|
84
|
84
|
$parsedRoutes = $this->processRoutes($generator, $routes); |
|
85
|
85
|
$parsedRoutes = collect($parsedRoutes)->groupBy('group') |
|
86
|
|
- ->sortBy(static function ($group) { |
|
|
86
|
+ ->sortBy(static function($group) { |
|
87
|
87
|
/* @var $group Collection */ |
|
88
|
88
|
return $group->first()['group']; |
|
89
|
89
|
}, SORT_NATURAL); |
|
@@ -99,19 +99,19 @@ discard block |
|
|
block discarded – undo |
|
99
|
99
|
private function writeMarkdown($parsedRoutes) |
|
100
|
100
|
{ |
|
101
|
101
|
$outputPath = $this->docConfig->get('output'); |
|
102
|
|
- $targetFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'index.md'; |
|
103
|
|
- $compareFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'.compare.md'; |
|
104
|
|
- $prependFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'prepend.md'; |
|
105
|
|
- $appendFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'append.md'; |
|
|
102
|
+ $targetFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . 'index.md'; |
|
|
103
|
+ $compareFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . '.compare.md'; |
|
|
104
|
+ $prependFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . 'prepend.md'; |
|
|
105
|
+ $appendFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . 'append.md'; |
|
106
|
106
|
|
|
107
|
107
|
$infoText = view('apidoc::partials.info') |
|
108
|
108
|
->with('outputPath', ltrim($outputPath, 'public/')) |
|
109
|
109
|
->with('showPostmanCollectionButton', $this->shouldGeneratePostmanCollection()); |
|
110
|
110
|
|
|
111
|
111
|
$settings = ['languages' => $this->docConfig->get('example_languages')]; |
|
112
|
|
- $parsedRouteOutput = $parsedRoutes->map(function ($routeGroup) use ($settings) { |
|
113
|
|
- return $routeGroup->map(function ($route) use ($settings) { |
|
114
|
|
- if (count($route['cleanBodyParameters']) && ! isset($route['headers']['Content-Type'])) { |
|
|
112
|
+ $parsedRouteOutput = $parsedRoutes->map(function($routeGroup) use ($settings) { |
|
|
113
|
+ return $routeGroup->map(function($route) use ($settings) { |
|
|
114
|
+ if (count($route['cleanBodyParameters']) && !isset($route['headers']['Content-Type'])) { |
|
115
|
115
|
$route['headers']['Content-Type'] = 'application/json'; |
|
116
|
116
|
} |
|
117
|
117
|
$route['output'] = (string) view('apidoc::partials.route') |
|
@@ -138,16 +138,16 @@ discard block |
|
|
block discarded – undo |
|
138
|
138
|
$frontmatter = trim($generatedFrontmatter[1], "\n"); |
|
139
|
139
|
} |
|
140
|
140
|
|
|
141
|
|
- $parsedRouteOutput->transform(function ($routeGroup) use ($generatedDocumentation, $compareDocumentation) { |
|
142
|
|
- return $routeGroup->transform(function ($route) use ($generatedDocumentation, $compareDocumentation) { |
|
143
|
|
- if (preg_match('/<!-- START_'.$route['id'].' -->(.*)<!-- END_'.$route['id'].' -->/is', $generatedDocumentation, $existingRouteDoc)) { |
|
144
|
|
- $routeDocumentationChanged = (preg_match('/<!-- START_'.$route['id'].' -->(.*)<!-- END_'.$route['id'].' -->/is', $compareDocumentation, $lastDocWeGeneratedForThisRoute) && $lastDocWeGeneratedForThisRoute[1] !== $existingRouteDoc[1]); |
|
|
141
|
+ $parsedRouteOutput->transform(function($routeGroup) use ($generatedDocumentation, $compareDocumentation) { |
|
|
142
|
+ return $routeGroup->transform(function($route) use ($generatedDocumentation, $compareDocumentation) { |
|
|
143
|
+ if (preg_match('/<!-- START_' . $route['id'] . ' -->(.*)<!-- END_' . $route['id'] . ' -->/is', $generatedDocumentation, $existingRouteDoc)) { |
|
|
144
|
+ $routeDocumentationChanged = (preg_match('/<!-- START_' . $route['id'] . ' -->(.*)<!-- END_' . $route['id'] . ' -->/is', $compareDocumentation, $lastDocWeGeneratedForThisRoute) && $lastDocWeGeneratedForThisRoute[1] !== $existingRouteDoc[1]); |
|
145
|
145
|
if ($routeDocumentationChanged === false || $this->option('force')) { |
|
146
|
146
|
if ($routeDocumentationChanged) { |
|
147
|
|
- $this->warn('Discarded manual changes for route ['.implode(',', $route['methods']).'] '.$route['uri']); |
|
|
147
|
+ $this->warn('Discarded manual changes for route [' . implode(',', $route['methods']) . '] ' . $route['uri']); |
|
148
|
148
|
} |
|
149
|
149
|
} else { |
|
150
|
|
- $this->warn('Skipping modified route ['.implode(',', $route['methods']).'] '.$route['uri']); |
|
|
150
|
+ $this->warn('Skipping modified route [' . implode(',', $route['methods']) . '] ' . $route['uri']); |
|
151
|
151
|
$route['modified_output'] = $existingRouteDoc[0]; |
|
152
|
152
|
} |
|
153
|
153
|
} |
|
@@ -158,9 +158,9 @@ discard block |
|
|
block discarded – undo |
|
158
|
158
|
} |
|
159
|
159
|
|
|
160
|
160
|
$prependFileContents = file_exists($prependFile) |
|
161
|
|
- ? file_get_contents($prependFile)."\n" : ''; |
|
|
161
|
+ ? file_get_contents($prependFile) . "\n" : ''; |
|
162
|
162
|
$appendFileContents = file_exists($appendFile) |
|
163
|
|
- ? "\n".file_get_contents($appendFile) : ''; |
|
|
163
|
+ ? "\n" . file_get_contents($appendFile) : ''; |
|
164
|
164
|
|
|
165
|
165
|
$documentarian = new Documentarian(); |
|
166
|
166
|
|
|
@@ -174,7 +174,7 @@ discard block |
|
|
block discarded – undo |
|
174
|
174
|
->with('showPostmanCollectionButton', $this->shouldGeneratePostmanCollection()) |
|
175
|
175
|
->with('parsedRoutes', $parsedRouteOutput); |
|
176
|
176
|
|
|
177
|
|
- if (! is_dir($outputPath)) { |
|
|
177
|
+ if (!is_dir($outputPath)) { |
|
178
|
178
|
$documentarian->create($outputPath); |
|
179
|
179
|
} |
|
180
|
180
|
|
|
@@ -194,24 +194,24 @@ discard block |
|
|
block discarded – undo |
|
194
|
194
|
|
|
195
|
195
|
file_put_contents($compareFile, $compareMarkdown); |
|
196
|
196
|
|
|
197
|
|
- $this->info('Wrote index.md to: '.$outputPath); |
|
|
197
|
+ $this->info('Wrote index.md to: ' . $outputPath); |
|
198
|
198
|
|
|
199
|
199
|
$this->info('Generating API HTML code'); |
|
200
|
200
|
|
|
201
|
201
|
$documentarian->generate($outputPath); |
|
202
|
202
|
|
|
203
|
|
- $this->info('Wrote HTML documentation to: '.$outputPath.'/index.html'); |
|
|
203
|
+ $this->info('Wrote HTML documentation to: ' . $outputPath . '/index.html'); |
|
204
|
204
|
|
|
205
|
205
|
if ($this->shouldGeneratePostmanCollection()) { |
|
206
|
206
|
$this->info('Generating Postman collection'); |
|
207
|
207
|
|
|
208
|
|
- file_put_contents($outputPath.DIRECTORY_SEPARATOR.'collection.json', $this->generatePostmanCollection($parsedRoutes)); |
|
|
208
|
+ file_put_contents($outputPath . DIRECTORY_SEPARATOR . 'collection.json', $this->generatePostmanCollection($parsedRoutes)); |
|
209
|
209
|
} |
|
210
|
210
|
|
|
211
|
211
|
if ($logo = $this->docConfig->get('logo')) { |
|
212
|
212
|
copy( |
|
213
|
213
|
$logo, |
|
214
|
|
- $outputPath.DIRECTORY_SEPARATOR.'images'.DIRECTORY_SEPARATOR.'logo.png' |
|
|
214
|
+ $outputPath . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'logo.png' |
|
215
|
215
|
); |
|
216
|
216
|
} |
|
217
|
217
|
} |
|
@@ -230,9 +230,9 @@ discard block |
|
|
block discarded – undo |
|
230
|
230
|
/** @var Route $route */ |
|
231
|
231
|
if ($this->isValidRoute($route) && $this->isRouteVisibleForDocumentation($route->getAction())) { |
|
232
|
232
|
$parsedRoutes[] = $generator->processRoute($route, $routeItem['apply']); |
|
233
|
|
- $this->info('Processed route: ['.implode(',', $generator->getMethods($route)).'] '.$generator->getUri($route)); |
|
|
233
|
+ $this->info('Processed route: [' . implode(',', $generator->getMethods($route)) . '] ' . $generator->getUri($route)); |
|
234
|
234
|
} else { |
|
235
|
|
- $this->warn('Skipping route: ['.implode(',', $generator->getMethods($route)).'] '.$generator->getUri($route)); |
|
|
235
|
+ $this->warn('Skipping route: [' . implode(',', $generator->getMethods($route)) . '] ' . $generator->getUri($route)); |
|
236
|
236
|
} |
|
237
|
237
|
} |
|
238
|
238
|
|
|
@@ -251,7 +251,7 @@ discard block |
|
|
block discarded – undo |
|
251
|
251
|
$action = implode('@', $action); |
|
252
|
252
|
} |
|
253
|
253
|
|
|
254
|
|
- return ! is_callable($action) && ! is_null($action); |
|
|
254
|
+ return !is_callable($action) && !is_null($action); |
|
255
|
255
|
} |
|
256
|
256
|
|
|
257
|
257
|
/** |
|
@@ -266,7 +266,7 @@ discard block |
|
|
block discarded – undo |
|
266
|
266
|
list($class, $method) = Utils::getRouteActionUses($action); |
|
267
|
267
|
$reflection = new ReflectionClass($class); |
|
268
|
268
|
|
|
269
|
|
- if (! $reflection->hasMethod($method)) { |
|
|
269
|
+ if (!$reflection->hasMethod($method)) { |
|
270
|
270
|
return false; |
|
271
|
271
|
} |
|
272
|
272
|
|
|
@@ -276,7 +276,7 @@ discard block |
|
|
block discarded – undo |
|
276
|
276
|
$phpdoc = new DocBlock($comment); |
|
277
|
277
|
|
|
278
|
278
|
return collect($phpdoc->getTags()) |
|
279
|
|
- ->filter(function ($tag) { |
|
|
279
|
+ ->filter(function($tag) { |
|
280
|
280
|
return $tag->getName() === 'hideFromAPIDocumentation'; |
|
281
|
281
|
}) |
|
282
|
282
|
->isEmpty(); |