Completed
Push — master ( 8c7ac3...548896 )
by Marcel
02:06
created

DingoGenerator::prepareMiddleware()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 2
nc 1
nop 1
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) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
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  boolean $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
    protected function getUri($route)
75
    {
76
        return $route->uri();
77
    }
78
}
79