1 | <?php |
||
39 | final class ResponseStatusLine implements StatusLine |
||
40 | { |
||
41 | /** |
||
42 | * The actual response code. |
||
43 | * |
||
44 | * @var int |
||
45 | */ |
||
46 | private $code; |
||
47 | |||
48 | /** |
||
49 | * The reason phrase. |
||
50 | * |
||
51 | * @var string |
||
52 | */ |
||
53 | private $reason; |
||
54 | |||
55 | /** |
||
56 | * ResponseStatusLine constructor. |
||
57 | * @param int $code The HTTP response code |
||
58 | * @param string $reason The reason phrase |
||
59 | */ |
||
60 | public function __construct($code, $reason) |
||
65 | |||
66 | |||
67 | /** |
||
68 | * Return the response code. |
||
69 | * |
||
70 | * @return int |
||
71 | */ |
||
72 | public function statusCode() |
||
76 | |||
77 | /** |
||
78 | * Return the reason phrase |
||
79 | * |
||
80 | * @return string |
||
81 | */ |
||
82 | public function reasonPhrase() |
||
86 | |||
87 | /** |
||
88 | * Add the status code and reason phrase to a Response. |
||
89 | * |
||
90 | * @param ResponseInterface $response The response |
||
91 | * @return ResponseInterface |
||
92 | */ |
||
93 | public function response(ResponseInterface $response) |
||
100 | |||
101 | /** |
||
102 | * Return the status class of the response code. |
||
103 | * |
||
104 | * @return int |
||
105 | */ |
||
106 | public function statusClass() |
||
110 | |||
111 | /** |
||
112 | * Helper to establish if the class of the status code |
||
113 | * is informational (1xx). |
||
114 | * |
||
115 | * @return bool |
||
116 | */ |
||
117 | public function isInformational() |
||
121 | |||
122 | /** |
||
123 | * Helper to establish if the class of the status code |
||
124 | * is successful (2xx). |
||
125 | * |
||
126 | * @return bool |
||
127 | */ |
||
128 | public function isSuccessful() |
||
132 | |||
133 | /** |
||
134 | * Helper to establish if the class of the status code |
||
135 | * is redirection (3xx). |
||
136 | * |
||
137 | * @return bool |
||
138 | */ |
||
139 | public function isRedirection() |
||
143 | |||
144 | /** |
||
145 | * Helper to establish if the class of the status code |
||
146 | * is client error (4xx). |
||
147 | * |
||
148 | * @return bool |
||
149 | */ |
||
150 | public function isClientError() |
||
154 | |||
155 | /** |
||
156 | * Helper to establish if the class of the status code |
||
157 | * is server error (5xx). |
||
158 | * |
||
159 | * @return bool |
||
160 | */ |
||
161 | public function isServerError() |
||
165 | |||
166 | /** |
||
167 | * Set the code. Used in constructor to ensure the code meets the |
||
168 | * requirements for a status code. |
||
169 | * |
||
170 | * @param int $code The status code |
||
171 | * @throws InvalidStatusCodeException If the status code is invalid |
||
172 | */ |
||
173 | private function setCode($code) |
||
185 | |||
186 | /** |
||
187 | * Test whether the response class matches the class passed to it. |
||
188 | * |
||
189 | * @param int $class The class of the response code |
||
190 | * @return bool |
||
191 | */ |
||
192 | private function isStatusClass($class) |
||
196 | } |
||
197 |