|
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
|
2 |
|
public function getStatus(): string |
|
74
|
|
|
{ |
|
75
|
2 |
|
return $this->status; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
2 |
|
public function setStatus(string $status): self |
|
79
|
|
|
{ |
|
80
|
2 |
|
$this->status = $status; |
|
81
|
2 |
|
return $this; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
2 |
|
public function getErrorMessage(): string |
|
85
|
|
|
{ |
|
86
|
2 |
|
return $this->errorMessage; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
1 |
|
public function setErrorMessage(string $errorMessage): self |
|
90
|
|
|
{ |
|
91
|
1 |
|
$this->errorMessage = $errorMessage; |
|
92
|
1 |
|
return $this; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
2 |
|
public function getErrorCode(): ?int |
|
96
|
|
|
{ |
|
97
|
2 |
|
return $this->errorCode; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
1 |
|
public function setErrorCode(int $errorCode): self |
|
101
|
|
|
{ |
|
102
|
1 |
|
$this->errorCode = $errorCode; |
|
103
|
1 |
|
return $this; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
2 |
|
public function getData(): ?array |
|
107
|
|
|
{ |
|
108
|
2 |
|
return $this->data; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
1 |
|
public function setData(?array $data): self |
|
112
|
|
|
{ |
|
113
|
1 |
|
$this->data = $data; |
|
114
|
1 |
|
return $this; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
2 |
|
public function toArray(): array |
|
118
|
|
|
{ |
|
119
|
2 |
|
return [ |
|
120
|
2 |
|
'status' => $this->getStatus(), |
|
121
|
2 |
|
'error_message' => $this->getErrorMessage(), |
|
122
|
2 |
|
'error_code' => $this->getErrorCode(), |
|
123
|
2 |
|
'data' => $this->getData(), |
|
124
|
2 |
|
]; |
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
|