-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApache.php
82 lines (71 loc) · 2.59 KB
/
Apache.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
<?php
namespace Ducks\Component\Apache {
/**
* @see http://php.net/manual/en/ref.apache.php
*/
class Apache {
/**
* Use for internal cache
* @var array
*/
protected $requestHeaders;
/**
* Use for internal cache
* @var array
*/
protected $responseHeaders;
/**
* Constructor
*/
public function __construct() {
$this->requestHeaders = array();
$this->responseHeaders = array();
}
/**
* Fetch all HTTP request headers
*
* @return mixed<array|boolean> An associative array of all the HTTP headers in the current request, or FALSE on failure.
*/
public function requestHeaders() {
if (empty($this->requestHeaders)) {
foreach ($_SERVER as $name => $value) {
if (substr($name, 0, 5) == 'HTTP_') {
$name = str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))));
$this->requestHeaders[$name] = $value;
} elseif ($name == 'CONTENT_TYPE') {
$this->requestHeaders['Content-Type'] = $value;
} elseif ($name == 'CONTENT_LENGTH') {
$this->requestHeaders["Content-Length"] = $value;
}
}
}
return (!empty($this->requestHeaders)) ? $this->requestHeaders : false;
}
/**
* Fetch all HTTP request headers
*
* This function is an alias for requestHeaders()
*
* @return mixed<array|boolean> An associative array of all the HTTP headers in the current request, or FALSE on failure.
* @see Ducks\Component\Apache\Apache::requestHeaders
*/
public function getAllHeaders() {
return $this->requestHeaders();
}
/**
* Fetch all HTTP response headers
*
* @return mixed<array|boolean> An array of all Apache response headers on success or FALSE on failure.
*/
public function responseHeaders() {
if (empty($this->responseHeaders)) {
$headers = headers_list();
foreach ($headers as $header) {
$header = explode(':', $header);
$this->responseHeaders[array_shift($header)] = trim(implode(':', $header));
}
}
return (!empty($this->responseHeaders)) ? $this->responseHeaders : false;
}
}
}