-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathResponse.php
75 lines (58 loc) · 1.19 KB
/
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
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
<?php
declare(strict_types=1);
namespace Milo\Github\Http;
use Milo\Github;
/**
* HTTP response envelope.
*
* @author Miloslav Hůla (https://github.com/milo)
*/
class Response extends Message
{
/** HTTP 1.1 code */
public const
S200_OK = 200,
S301_MOVED_PERMANENTLY = 301,
S302_FOUND = 302,
S304_NOT_MODIFIED = 304,
S307_TEMPORARY_REDIRECT = 307,
S400_BAD_REQUEST = 400,
S401_UNAUTHORIZED = 401,
S403_FORBIDDEN = 403,
S404_NOT_FOUND = 404,
S422_UNPROCESSABLE_ENTITY = 422;
private ?Response $previous = null;
public function __construct(
private int $code,
array $headers,
?string $content,
) {
parent::__construct($headers, $content);
}
/**
* HTTP response status code.
*/
public function getCode(): int
{
return $this->code;
}
public function isCode(int $code): bool
{
return $this->code === $code;
}
public function getPrevious(): ?Response
{
return $this->previous;
}
/**
* @throws Github\LogicException
*/
public function setPrevious(?Response $previous = null): static
{
if ($this->previous) {
throw new Github\LogicException('Previous response is already set.');
}
$this->previous = $previous;
return $this;
}
}