-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathResponse.php
91 lines (73 loc) · 1.32 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
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 */
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;
/** @var int */
private $code;
/** @var Response */
private $previous;
/**
* @param int
* @param array
* @param string
*/
public function __construct($code, array $headers, $content)
{
$this->code = (int) $code;
parent::__construct($headers, $content);
}
/**
* HTTP code.
* @return int
*/
public function getCode()
{
return $this->code;
}
/**
* @param int
* @return bool
*/
public function isCode($code)
{
return $this->code === (int) $code;
}
/**
* @return Response|NULL
*/
public function getPrevious()
{
return $this->previous;
}
/**
* @return self
*
* @throws Github\LogicException
*/
public function setPrevious(Response $previous = NULL)
{
if ($this->previous) {
throw new Github\LogicException('Previous response is already set.');
}
$this->previous = $previous;
return $this;
}
}