Skip to content

Commit

Permalink
feat: register HTTP_AUTHORIZATION to header if available (#364)
Browse files Browse the repository at this point in the history
* feat: register `HTTP_AUTHORIZATION` to header if available

- add new method  `RequestFactory::capture()`
- deprecated `getFromGloball` and added `getFromGlobal`

* fix: php stan
  • Loading branch information
SonyPradana authored Jul 13, 2024
1 parent 891b06c commit ee34894
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/System/Http/RequestFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,25 @@

class RequestFactory
{
/**
* Helper to create request from global.
*/
public static function capture(): Request
{
return (new self())->getFromGlobal();
}

/**
* Derecated couse typo.
*
* @deprecated v0.35.5 Use `getFromGlobal()` instead
*/
public function getFromGloball(): Request
{
return $this->getFromGlobal();
}

public function getFromGlobal(): Request
{
return new Request(
$_SERVER['REQUEST_URI'] ?? '',
Expand Down Expand Up @@ -44,7 +62,9 @@ private function getHeaders(): array
}

if (!isset($headers['Authorization'])) {
if (isset($_SERVER['REDIRECT_HTTP_AUTHORIZATION'])) {
if (isset($_SERVER['HTTP_AUTHORIZATION'])) {
$headers['Authorization'] = $_SERVER['HTTP_AUTHORIZATION'];
} elseif (isset($_SERVER['REDIRECT_HTTP_AUTHORIZATION'])) {
$headers['Authorization'] = $_SERVER['REDIRECT_HTTP_AUTHORIZATION'];
} elseif (isset($_SERVER['PHP_AUTH_USER'])) {
$basic_pass = $_SERVER['PHP_AUTH_PW'] ?? '';
Expand Down

0 comments on commit ee34894

Please sign in to comment.