-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAPIResponse.php
49 lines (44 loc) · 952 Bytes
/
APIResponse.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
namespace App\Core\Framework\Structures;
class APIResponse{
/**
* HTTP Response code
*
* @var int
*/
public int $code;
/**
* Represents the message associated with the operation.
*
* @var string
*/
public string $message;
/**
* Represents the data associated with the operation.
*
* @var array
*/
public array $data;
/**
* APIResponse constructor.
*
* @param int $code The HTTP Response code in response body.
* @param string $message The message associated with the operation.
* @param array $data The data associated with the operation.
*/
public function __construct(int $code, string $message, array $data = [])
{
$this->code = $code;
$this->message = $message;
$this->data = $data;
}
/**
* Converts the APIResponse object to JSON format.
*
* @return string The JSON representation of the APIResponse object.
*/
public function __toJSON()
{
return json_encode($this);
}
}