Skip to content

Commit

Permalink
Merge pull request #60 from webrium:Add-Header-Class
Browse files Browse the repository at this point in the history
feat: add header class
  • Loading branch information
parsgit authored Aug 2, 2024
2 parents bca1212 + df780f1 commit 481cd61
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/Header.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
namespace webrium;

class Header
{

public static function all(){
return getallheaders();
}



/**
* Get header Authorization
*/
public static function getAuthorizationHeader()
{
$headers = null;
if (isset($_SERVER['Authorization'])) {
$headers = trim($_SERVER["Authorization"]);
} else if (isset($_SERVER['HTTP_AUTHORIZATION'])) { //Nginx or fast CGI
$headers = trim($_SERVER["HTTP_AUTHORIZATION"]);
} elseif (function_exists('apache_request_headers')) {
$requestHeaders = apache_request_headers();
// 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)
$requestHeaders = array_combine(array_map('ucwords', array_keys($requestHeaders)), array_values($requestHeaders));

if (isset($requestHeaders['Authorization'])) {
$headers = trim($requestHeaders['Authorization']);
}
}
return $headers;
}

/**
* get access token from header
*/
public static function getBearerToken()
{
$headers = self::getAuthorizationHeader();

if (!empty($headers)) {
return substr($headers, 7);
}

return false;
}

}

0 comments on commit 481cd61

Please sign in to comment.