1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Rest Response |
5
|
|
|
* |
6
|
|
|
* @link https://github.com/MelquesPaiva/rest-response for the canonical source repository |
7
|
|
|
* @copyright Copyright (c) MelquesPaiva |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace MelquesPaiva\RestResponse\HttpResponse; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class Success |
14
|
|
|
* @package MelquesPaiva\RestResponse\HttpResponse |
15
|
|
|
*/ |
16
|
|
|
abstract class HttpResponse |
17
|
|
|
{ |
18
|
|
|
/** @var int $statusCode */ |
19
|
|
|
protected int $statusCode; |
20
|
|
|
|
21
|
|
|
/** @var string $message */ |
22
|
|
|
protected string $message; |
23
|
|
|
|
24
|
|
|
/** @var array $data */ |
25
|
|
|
protected array $data = []; |
26
|
|
|
|
27
|
|
|
/** @var string $type */ |
28
|
|
|
protected string $type; |
29
|
|
|
|
30
|
|
|
/** @var string $parameter */ |
31
|
|
|
protected string $parameter = ""; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Request Status Code |
35
|
|
|
* |
36
|
|
|
* @param integer $statusCode |
37
|
|
|
* @return HttpResponse |
38
|
|
|
*/ |
39
|
|
|
public function setStatusCode(int $statusCode): HttpResponse |
40
|
|
|
{ |
41
|
|
|
$this->statusCode = $statusCode; |
42
|
|
|
return $this; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Get the value of statusCode |
47
|
|
|
* |
48
|
|
|
* @return int |
49
|
|
|
*/ |
50
|
|
|
public function getStatusCode(): int |
51
|
|
|
{ |
52
|
|
|
return $this->statusCode; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Set message |
57
|
|
|
* |
58
|
|
|
* @param string $message |
59
|
|
|
* @return HttpResponse |
60
|
|
|
*/ |
61
|
|
|
public function setMessage(string $message): HttpResponse |
62
|
|
|
{ |
63
|
|
|
$this->message = $message; |
64
|
|
|
return $this; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Get the value of message |
69
|
|
|
* |
70
|
|
|
* @return string |
71
|
|
|
*/ |
72
|
|
|
public function getMessage(): string |
73
|
|
|
{ |
74
|
|
|
return $this->message; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Set data |
79
|
|
|
* |
80
|
|
|
* @param array $data |
81
|
|
|
* @return HttpResponse |
82
|
|
|
*/ |
83
|
|
|
public function setData(array $data): HttpResponse |
84
|
|
|
{ |
85
|
|
|
$this->data = $data; |
86
|
|
|
return $this; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Get the value of data |
91
|
|
|
* |
92
|
|
|
* @return array |
93
|
|
|
*/ |
94
|
|
|
public function getData(): array |
95
|
|
|
{ |
96
|
|
|
return $this->data; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Set type |
101
|
|
|
* |
102
|
|
|
* @param array $type |
103
|
|
|
* @return HttpResponse |
104
|
|
|
*/ |
105
|
|
|
public function setType(string $type): HttpResponse |
106
|
|
|
{ |
107
|
|
|
$this->type = $type; |
108
|
|
|
return $this; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Get the value of type |
113
|
|
|
* |
114
|
|
|
* @return string |
115
|
|
|
*/ |
116
|
|
|
public function getType(): string |
117
|
|
|
{ |
118
|
|
|
return $this->type; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Set parameter |
123
|
|
|
* |
124
|
|
|
* @param array $parameter |
125
|
|
|
* @return HttpResponse |
126
|
|
|
*/ |
127
|
|
|
public function setParameter(string $parameter): HttpResponse |
128
|
|
|
{ |
129
|
|
|
$this->parameter = $parameter; |
130
|
|
|
return $this; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Get the value of parameter |
135
|
|
|
* |
136
|
|
|
* @return string |
137
|
|
|
*/ |
138
|
|
|
public function getParameter() |
139
|
|
|
{ |
140
|
|
|
return $this->parameter; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* Class to array |
145
|
|
|
* |
146
|
|
|
* @return array |
147
|
|
|
*/ |
148
|
|
|
public abstract function toArray(): array; |
149
|
|
|
} |
150
|
|
|
|