-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathResponse.php
49 lines (39 loc) · 940 Bytes
/
Response.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 Rodri\SimpleRouter;
use Rodri\SimpleRouter\Helpers\StatusCode;
/**
* Class Response
* @package Rodri\SimpleRouter
* @author Rodrigo Andrade
* @version 1.0.0
*/
class Response
{
public const NONE_RESPONSE = '';
public const INVALID_RESPONSE = 'NONE_VALUE_NULL';
public function __construct(
private mixed $response = Response::NONE_RESPONSE,
String $statusCode = StatusCode::OK,
)
{
header($statusCode);
}
/**
* Check if has some response inavlid value.
* @return bool
*/
public function hasInvalidResponse(): bool
{
return $this->response !== Response::INVALID_RESPONSE;
}
public function __toString(): string
{
if(empty($this->response)) {
return PHP_EOL;
}
if($this->hasInvalidResponse()) {
return json_encode($this->response);
}
return '';
}
}