Completed
Push — master ( e8bb65...b9989c )
by Mauro
16:58
created

BaseController::jsonResponse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 3
1
<?php
2
3
namespace App\Controller;
4
5
/**
6
 * Base Controller Class.
7
 */
8
abstract class BaseController
9
{
10
    const API_VERSION = '17.04';
11
12
    protected $logger;
13
    protected $database;
14
    protected $request;
15
    protected $response;
16
    protected $args;
17
18
    /**
19
     * @param Request $request
20
     * @param Response $response
21
     * @param array $args
22
     */
23
    protected function setParams($request, $response, $args)
24
    {
25
        $this->request = $request;
26
        $this->response = $response;
27
        $this->args = $args;
28
        $info = [
29
            'method' => $this->request->getAttribute('route')->getMethods(),
30
            'path' => $this->request->getUri()->getPath(),
31
            'input' => $this->request->getParsedBody(),
32
            'args' => $this->args,
33
        ];
34
        $this->logger->info(json_encode($info));
35
    }
36
37
    /**
38
     * Send response with json as standard format.
39
     *
40
     * @param string $status
41
     * @param mixed $message
42
     * @param int $code
43
     * @return array $response
44
     */
45
    protected function jsonResponse($status, $message, $code)
46
    {
47
        $result = [
48
            'code' => $code,
49
            'status' => $status,
50
            'message' => $message,
51
        ];
52
53
        return $this->response->withJson($result, $code, JSON_PRETTY_PRINT);
54
    }
55
}
56