Skip to content

Commit 481cd61

Browse files
authored
Merge pull request #60 from webrium:Add-Header-Class
feat: add header class
2 parents bca1212 + df780f1 commit 481cd61

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

src/Header.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
namespace webrium;
3+
4+
class Header
5+
{
6+
7+
public static function all(){
8+
return getallheaders();
9+
}
10+
11+
12+
13+
/**
14+
* Get header Authorization
15+
*/
16+
public static function getAuthorizationHeader()
17+
{
18+
$headers = null;
19+
if (isset($_SERVER['Authorization'])) {
20+
$headers = trim($_SERVER["Authorization"]);
21+
} else if (isset($_SERVER['HTTP_AUTHORIZATION'])) { //Nginx or fast CGI
22+
$headers = trim($_SERVER["HTTP_AUTHORIZATION"]);
23+
} elseif (function_exists('apache_request_headers')) {
24+
$requestHeaders = apache_request_headers();
25+
// Server-side fix for bug in old Android versions (a nice side-effect of this fix means we don't care about capitalization for Authorization)
26+
$requestHeaders = array_combine(array_map('ucwords', array_keys($requestHeaders)), array_values($requestHeaders));
27+
28+
if (isset($requestHeaders['Authorization'])) {
29+
$headers = trim($requestHeaders['Authorization']);
30+
}
31+
}
32+
return $headers;
33+
}
34+
35+
/**
36+
* get access token from header
37+
*/
38+
public static function getBearerToken()
39+
{
40+
$headers = self::getAuthorizationHeader();
41+
42+
if (!empty($headers)) {
43+
return substr($headers, 7);
44+
}
45+
46+
return false;
47+
}
48+
49+
}

0 commit comments

Comments
 (0)