1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace bSecure\UniversalCheckout\Helpers; |
4
|
|
|
|
5
|
|
|
use Illuminate\Http\JsonResponse; |
|
|
|
|
6
|
|
|
|
7
|
|
|
class ApiResponseHandler |
8
|
|
|
{ |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @param array $body |
12
|
|
|
* @param string $message |
13
|
|
|
* @return JsonResponse |
14
|
|
|
*/ |
15
|
|
|
public static function success($body = [], $message = "messages.general.success") |
16
|
|
|
{ |
17
|
|
|
|
18
|
|
|
return self::send( |
19
|
|
|
Http::$Codes[Http::SUCCESS], |
20
|
|
|
[Language::getMessage($message)], |
21
|
|
|
(object)$body, |
22
|
|
|
null |
23
|
|
|
); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @param $validationErrors (coudle be array of errors or validator object) |
|
|
|
|
28
|
|
|
* @param string $message |
29
|
|
|
* @return JsonResponse |
30
|
|
|
*/ |
31
|
|
|
public static function validationError($validationErrors, $message = "general.validation") |
|
|
|
|
32
|
|
|
{ |
33
|
|
|
|
34
|
|
|
$errorMessages = []; |
35
|
|
|
|
36
|
|
|
if (is_array($validationErrors)) { |
37
|
|
|
$errorMessages = array_values($validationErrors); |
38
|
|
|
} else { |
39
|
|
|
foreach ($validationErrors->getMessages() as $key => $errors) { |
40
|
|
|
$errorMessages = array_merge($errorMessages, $errors); |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
return self::send( |
45
|
|
|
Http::$Codes[Http::INPROCESSABLE], |
46
|
|
|
$errorMessages, |
47
|
|
|
(object)[], |
48
|
|
|
null |
49
|
|
|
); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @return JsonResponse |
54
|
|
|
*/ |
55
|
|
|
public static function authenticationError() |
56
|
|
|
{ |
57
|
|
|
|
58
|
|
|
return self::send( |
59
|
|
|
Http::$Codes[Http::UNAUTHORISED], |
60
|
|
|
[Language::getMessage("general.unauthenticated")], |
61
|
|
|
(object)[], |
62
|
|
|
null |
63
|
|
|
); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param string $message |
68
|
|
|
* @param null $exception |
|
|
|
|
69
|
|
|
* @param array $body |
70
|
|
|
* @return JsonResponse |
71
|
|
|
*/ |
72
|
|
|
public static function failure($message = 'general.error', $exception = null, $body = []) |
73
|
|
|
{ |
74
|
|
|
return self::send( |
75
|
|
|
Http::$Codes[Http::BAD_REQUEST], |
76
|
|
|
(gettype($message) == "array") ? $message : [Language::getMessage($message)], |
77
|
|
|
(object)$body, |
78
|
|
|
$exception |
79
|
|
|
); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @param $code |
84
|
|
|
* @param $message |
85
|
|
|
* @param $exception |
86
|
|
|
* @return JsonResponse |
87
|
|
|
*/ |
88
|
|
|
|
89
|
|
|
public static function exception($code, $message, $exception = null) |
90
|
|
|
{ |
91
|
|
|
return self::send( |
92
|
|
|
$code, |
93
|
|
|
[$message], |
94
|
|
|
[], |
95
|
|
|
$exception |
96
|
|
|
); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @param $status |
101
|
|
|
* @param $message |
102
|
|
|
* @param $body |
103
|
|
|
* @param $exception |
104
|
|
|
* @return JsonResponse |
105
|
|
|
*/ |
106
|
|
|
private static function send($status, $message, $body, $exception) |
107
|
|
|
{ |
108
|
|
|
|
109
|
|
|
return response()->json([ |
|
|
|
|
110
|
|
|
'status' => $status, |
111
|
|
|
'message' => $message, |
112
|
|
|
'body' => $body, |
113
|
|
|
'exception' => $exception |
114
|
|
|
], $status, [], JSON_UNESCAPED_UNICODE); |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths