1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace App\Http; |
6
|
|
|
|
7
|
|
|
use OpenApi\Annotations as OA; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @OA\Schema( |
11
|
|
|
* schema="Response", |
12
|
|
|
* ) |
13
|
|
|
* @OA\Schema( |
14
|
|
|
* schema="BadResponse", |
15
|
|
|
* allOf={ |
16
|
|
|
* @OA\Schema(ref="#/components/schemas/Response"), |
17
|
|
|
* @OA\Schema( |
18
|
|
|
* |
19
|
|
|
* @OA\Property( |
20
|
|
|
* property="status", |
21
|
|
|
* example="failed", |
22
|
|
|
* ), |
23
|
|
|
* @OA\Property(property="error_message", example="Error description message"), |
24
|
|
|
* @OA\Property(property="error_code", nullable=true, example=400), |
25
|
|
|
* @OA\Property( |
26
|
|
|
* property="data", |
27
|
|
|
* example=null |
28
|
|
|
* ), |
29
|
|
|
* ) |
30
|
|
|
* } |
31
|
|
|
* ) |
32
|
|
|
*/ |
33
|
|
|
final class ApiResponseData |
34
|
|
|
{ |
35
|
|
|
/** |
36
|
|
|
* @OA\Property( |
37
|
|
|
* property="status", |
38
|
|
|
* format="string", |
39
|
|
|
* example="success", |
40
|
|
|
* enum={"success", "failed"} |
41
|
|
|
* ) |
42
|
|
|
*/ |
43
|
|
|
private string $status = ''; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @OA\Property( |
47
|
|
|
* property="error_message", |
48
|
|
|
* format="string", |
49
|
|
|
* example="" |
50
|
|
|
* ) |
51
|
|
|
*/ |
52
|
|
|
private string $errorMessage = ''; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @OA\Property( |
56
|
|
|
* property="error_code", |
57
|
|
|
* format="integer", |
58
|
|
|
* nullable=true, |
59
|
|
|
* example=null |
60
|
|
|
* ) |
61
|
|
|
*/ |
62
|
|
|
private ?int $errorCode = null; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @OA\Property( |
66
|
|
|
* property="data", |
67
|
|
|
* type="object", |
68
|
|
|
* nullable=true, |
69
|
|
|
* ) |
70
|
|
|
*/ |
71
|
|
|
private ?array $data = null; |
72
|
|
|
|
73
|
|
|
public function getStatus(): string |
74
|
|
|
{ |
75
|
|
|
return $this->status; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function setStatus(string $status): self |
79
|
|
|
{ |
80
|
|
|
$this->status = $status; |
81
|
|
|
return $this; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function getErrorMessage(): string |
85
|
|
|
{ |
86
|
|
|
return $this->errorMessage; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function setErrorMessage(string $errorMessage): self |
90
|
|
|
{ |
91
|
|
|
$this->errorMessage = $errorMessage; |
92
|
|
|
return $this; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function getErrorCode(): ?int |
96
|
|
|
{ |
97
|
|
|
return $this->errorCode; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function setErrorCode(int $errorCode): self |
101
|
|
|
{ |
102
|
|
|
$this->errorCode = $errorCode; |
103
|
|
|
return $this; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
public function getData(): ?array |
107
|
|
|
{ |
108
|
|
|
return $this->data; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
public function setData(?array $data): self |
112
|
|
|
{ |
113
|
|
|
$this->data = $data; |
114
|
|
|
return $this; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
public function toArray(): array |
118
|
|
|
{ |
119
|
|
|
return [ |
120
|
|
|
'status' => $this->getStatus(), |
121
|
|
|
'error_message' => $this->getErrorMessage(), |
122
|
|
|
'error_code' => $this->getErrorCode(), |
123
|
|
|
'data' => $this->getData(), |
124
|
|
|
]; |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|