-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathResponseHttpUtils.php
More file actions
62 lines (54 loc) · 1.72 KB
/
ResponseHttpUtils.php
File metadata and controls
62 lines (54 loc) · 1.72 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
<?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 ResponseHttpUtils
{
/**
* @var array
*/
private array $defaultHeaders
= [
AbstractResponse::RESPONSE_OK => 'HTTP/1.1 200 OK',
AbstractResponse::RESPONSE_CREATED => 'HTTP/1.1 201 OK',
AbstractResponse::RESPONSE_NO_CONTENT => 'HTTP/1.1 204 OK',
AbstractResponse::RESPONSE_BAD_REQUEST => 'HTTP/1.1 400 Bad Request',
AbstractResponse::RESPONSE_UNAUTHORIZED => 'HTTP/1.1 401 Unauthorized',
AbstractResponse::RESPONSE_NOT_FOUND => 'HTTP/1.1 404 Not Found',
AbstractResponse::RESPONSE_NOT_ALLOWED => 'HTTP/1.1 405 Method Not Allowed',
AbstractResponse::RESPONSE_CONFLICT => 'HTTP/1.1 409 Conflict',
AbstractResponse::RESPONSE_INTERNAL_ERROR => 'HTTP/1.1 500 Internal Server Error',
];
/**
* @param int $code
*
* @return string
*/
public function getDefaultHeaderByCode(int $code): string
{
if (isset($this->defaultHeaders[$code])) {
return $this->defaultHeaders[$code];
}
throw new Exception\InvalidArgumentException(
sprintf(
'Header is not registered for the code "%d"',
$code
)
);
}
/**
* @param array $headers
*/
public function sendHeaders(array $headers)
{
foreach ($headers as $header) {
header($header);
}
}
}