1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Mpociot\ApiDoc\Generators; |
4
|
|
|
|
5
|
|
|
use Illuminate\Routing\Route; |
6
|
|
|
use Illuminate\Support\Facades\App; |
7
|
|
|
use Illuminate\Support\Facades\Request; |
8
|
|
|
|
9
|
|
|
class DingoGenerator extends AbstractGenerator |
10
|
|
|
{ |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @param \Illuminate\Routing\Route $route |
14
|
|
|
* @param array $bindings |
15
|
|
|
* |
16
|
|
|
* @return array |
17
|
|
|
*/ |
18
|
|
View Code Duplication |
public function processRoute(Route $route, $bindings = []) |
|
|
|
|
19
|
|
|
{ |
20
|
|
|
$response = $this->getRouteResponse($route, $bindings); |
21
|
|
|
|
22
|
|
|
$routeAction = $route->getAction(); |
23
|
|
|
$routeGroup = $this->getRouteGroup($routeAction['uses']); |
24
|
|
|
$routeDescription = $this->getRouteDescription($routeAction['uses']); |
25
|
|
|
|
26
|
|
|
if ($response->headers->get('Content-Type') === 'application/json') { |
27
|
|
|
$content = json_encode(json_decode($response->getContent()), JSON_PRETTY_PRINT); |
28
|
|
|
} else { |
29
|
|
|
$content = $response->getContent(); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
return $this->getParameters([ |
33
|
|
|
'resource' => $routeGroup, |
34
|
|
|
'title' => $routeDescription['short'], |
35
|
|
|
'description' => $routeDescription['long'], |
36
|
|
|
'methods' => $route->getMethods(), |
37
|
|
|
'uri' => $route->getUri(), |
38
|
|
|
'parameters' => [], |
39
|
|
|
'response' => $content, |
40
|
|
|
], $routeAction); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* {@inheritdoc} |
46
|
|
|
*/ |
47
|
|
|
public function callRoute($method, $uri, $parameters = [], $cookies = [], $files = [], $server = [], $content = null) |
48
|
|
|
{ |
49
|
|
|
return call_user_func_array([app('Dingo\Api\Dispatcher'), strtolower($method)], [$uri]); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* {@inheritdoc} |
54
|
|
|
*/ |
55
|
|
|
protected function getUri(Route $route) |
56
|
|
|
{ |
57
|
|
|
return $route->uri(); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.