1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Controller; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Base Controller. |
7
|
|
|
*/ |
8
|
|
|
abstract class BaseController |
9
|
|
|
{ |
10
|
|
|
const API_VERSION = '17.05'; |
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
|
|
|
$this->logRequest(); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
protected function logRequest() |
32
|
|
|
{ |
33
|
|
|
// $info = [ |
|
|
|
|
34
|
|
|
// 'method' => $this->request->getAttribute('route')->getMethods(), |
35
|
|
|
// 'path' => $this->request->getUri()->getPath(), |
36
|
|
|
// 'input' => $this->request->getParsedBody(), |
37
|
|
|
// 'args' => $this->args, |
38
|
|
|
// ]; |
39
|
|
|
|
40
|
|
|
|
41
|
|
|
$routeInfo = $this->request->getAttribute('routeInfo'); |
42
|
|
|
$route = $this->request->getAttribute('route'); |
43
|
|
|
|
44
|
|
|
$this->logger->info('**********'); |
45
|
|
|
$this->logger->info('* REQUEST: ' . $route->getCallable()[1]); |
46
|
|
|
$this->logger->info('* ' . $route->getMethods()[0] . ' ' . $routeInfo['request'][1]); |
47
|
|
|
$this->logger->info('* BODY: ' . json_encode($this->request->getParsedBody())); |
48
|
|
|
$this->logger->info('* ARGS: ' . json_encode($this->args)); |
49
|
|
|
|
50
|
|
|
// $routeName = $route->getName(); |
|
|
|
|
51
|
|
|
// $groups = $route->getGroups(); |
52
|
|
|
// $methods = $route->getMethods(); |
53
|
|
|
// $arguments = $route->getArguments(); |
54
|
|
|
// |
55
|
|
|
// var_dump($route->getCallable()[1]); |
56
|
|
|
// print "Route Info: " . print_r($route, true); |
57
|
|
|
// print "Route Name: " . print_r($routeName, true); |
58
|
|
|
// print "Route Groups: " . print_r($groups, true); |
59
|
|
|
// print "Route Methods: " . print_r($methods, true); |
60
|
|
|
// print "Route Arguments: " . print_r($arguments, true); |
61
|
|
|
// exit; |
62
|
|
|
// $this->logger->info(json_encode($info)); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Send response with json as standard format. |
67
|
|
|
* |
68
|
|
|
* @param string $status |
69
|
|
|
* @param mixed $message |
70
|
|
|
* @param int $code |
71
|
|
|
* @return array $response |
72
|
|
|
*/ |
73
|
|
|
protected function jsonResponse($status, $message, $code) |
74
|
|
|
{ |
75
|
|
|
$result = [ |
76
|
|
|
'code' => $code, |
77
|
|
|
'status' => $status, |
78
|
|
|
'message' => $message, |
79
|
|
|
]; |
80
|
|
|
// $this->logger->info(json_encode($result)); |
|
|
|
|
81
|
|
|
$this->logger->info('* RESPONSE: ' . json_encode($result)); |
82
|
|
|
$this->logger->info('**********'); |
83
|
|
|
|
84
|
|
|
return $this->response->withJson($result, $code, JSON_PRETTY_PRINT); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.