|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Mpociot\ApiDoc\Generators; |
|
4
|
|
|
|
|
5
|
|
|
use Exception; |
|
6
|
|
|
|
|
7
|
|
|
class DingoGenerator extends AbstractGenerator |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* @param \Illuminate\Routing\Route $route |
|
11
|
|
|
* @param array $bindings |
|
12
|
|
|
* @param array $headers |
|
13
|
|
|
* @param bool $withResponse |
|
14
|
|
|
* |
|
15
|
|
|
* @return array |
|
16
|
|
|
*/ |
|
17
|
|
|
public function processRoute($route, $bindings = [], $headers = [], $withResponse = true) |
|
18
|
|
|
{ |
|
19
|
|
|
$response = ''; |
|
20
|
|
|
|
|
21
|
|
|
if ($withResponse) { |
|
22
|
|
|
try { |
|
23
|
|
|
$response = $this->getRouteResponse($route, $bindings, $headers); |
|
24
|
|
|
} catch (Exception $e) { |
|
|
|
|
|
|
25
|
|
|
} |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
$routeAction = $route->getAction(); |
|
29
|
|
|
$routeGroup = $this->getRouteGroup($routeAction['uses']); |
|
30
|
|
|
$routeDescription = $this->getRouteDescription($routeAction['uses']); |
|
31
|
|
|
|
|
32
|
|
|
return $this->getParameters([ |
|
33
|
|
|
'id' => md5($route->uri().':'.implode($route->getMethods())), |
|
|
|
|
|
|
34
|
|
|
'resource' => $routeGroup, |
|
35
|
|
|
'title' => $routeDescription['short'], |
|
36
|
|
|
'description' => $routeDescription['long'], |
|
37
|
|
|
'methods' => $route->getMethods(), |
|
|
|
|
|
|
38
|
|
|
'uri' => $route->uri(), |
|
39
|
|
|
'parameters' => [], |
|
40
|
|
|
'response' => $response, |
|
41
|
|
|
], $routeAction, $bindings); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Prepares / Disables route middlewares. |
|
46
|
|
|
* |
|
47
|
|
|
* @param bool $disable |
|
48
|
|
|
* |
|
49
|
|
|
* @return void |
|
50
|
|
|
*/ |
|
51
|
|
|
public function prepareMiddleware($disable = true) |
|
52
|
|
|
{ |
|
53
|
|
|
// Not needed by Dingo |
|
54
|
|
|
return false; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* {@inheritdoc} |
|
59
|
|
|
*/ |
|
60
|
|
|
public function callRoute($method, $uri, $parameters = [], $cookies = [], $files = [], $server = [], $content = null) |
|
61
|
|
|
{ |
|
62
|
|
|
$dispatcher = app('Dingo\Api\Dispatcher')->raw(); |
|
63
|
|
|
|
|
64
|
|
|
collect($server)->map(function ($key, $value) use ($dispatcher) { |
|
65
|
|
|
$dispatcher->header($key, $value); |
|
66
|
|
|
}); |
|
67
|
|
|
|
|
68
|
|
|
return call_user_func_array([$dispatcher, strtolower($method)], [$uri]); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* {@inheritdoc} |
|
73
|
|
|
*/ |
|
74
|
|
|
public function getUri($route) |
|
75
|
|
|
{ |
|
76
|
|
|
return $route->uri(); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* {@inheritdoc} |
|
81
|
|
|
*/ |
|
82
|
|
|
public function getMethods($route) |
|
83
|
|
|
{ |
|
84
|
|
|
return $route->getMethods(); |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|