-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAbstractResponse.php
More file actions
99 lines (82 loc) · 1.85 KB
/
AbstractResponse.php
File metadata and controls
99 lines (82 loc) · 1.85 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
namespace Tiny\Http;
/*
* This file is part of the Tiny package.
*
* (c) Alex Ermashev <alexermashev@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
class AbstractResponse
{
const RESPONSE_OK = 200;
const RESPONSE_CREATED = 201;
const RESPONSE_NO_CONTENT = 204;
const RESPONSE_BAD_REQUEST = 400;
const RESPONSE_UNAUTHORIZED = 401;
const RESPONSE_NOT_FOUND = 404;
const RESPONSE_NOT_ALLOWED = 405;
const RESPONSE_CONFLICT = 409;
const RESPONSE_INTERNAL_ERROR = 500;
const RESPONSE_TYPE_TEXT = 'text/plain';
const RESPONSE_TYPE_HTML = 'text/html';
const RESPONSE_TYPE_JSON = 'application/json';
/**
* @var int
*/
protected int $code = self::RESPONSE_OK;
/**
* @var string
*/
protected string $responseType = self::RESPONSE_TYPE_HTML;
/**
* @var mixed
*/
protected $response;
/**
* @param int $code
*
* @return $this
*/
public function setCode(int $code): self
{
$this->code = $code;
return $this;
}
/**
* @param string $responseType
*
* @return $this
*/
public function setResponseType(string $responseType)
{
$this->responseType = $responseType;
return $this;
}
/**
* @param mixed $response
*
* @return $this
*/
public function setResponse($response)
{
$this->response = $response;
return $this;
}
/**
* @return mixed
*/
public function getResponse()
{
return $this->response;
}
/**
* @return mixed
*/
public function getResponseForDisplaying()
{
return is_object($this->response) ? $this->response->__toString()
: $this->response;
}
}