Skip to content

Commit ee34894

Browse files
authored
feat: register HTTP_AUTHORIZATION to header if available (#364)
* feat: register `HTTP_AUTHORIZATION` to header if available - add new method `RequestFactory::capture()` - deprecated `getFromGloball` and added `getFromGlobal` * fix: php stan
1 parent 891b06c commit ee34894

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/System/Http/RequestFactory.php

+21-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,25 @@
66

77
class RequestFactory
88
{
9+
/**
10+
* Helper to create request from global.
11+
*/
12+
public static function capture(): Request
13+
{
14+
return (new self())->getFromGlobal();
15+
}
16+
17+
/**
18+
* Derecated couse typo.
19+
*
20+
* @deprecated v0.35.5 Use `getFromGlobal()` instead
21+
*/
922
public function getFromGloball(): Request
23+
{
24+
return $this->getFromGlobal();
25+
}
26+
27+
public function getFromGlobal(): Request
1028
{
1129
return new Request(
1230
$_SERVER['REQUEST_URI'] ?? '',
@@ -44,7 +62,9 @@ private function getHeaders(): array
4462
}
4563

4664
if (!isset($headers['Authorization'])) {
47-
if (isset($_SERVER['REDIRECT_HTTP_AUTHORIZATION'])) {
65+
if (isset($_SERVER['HTTP_AUTHORIZATION'])) {
66+
$headers['Authorization'] = $_SERVER['HTTP_AUTHORIZATION'];
67+
} elseif (isset($_SERVER['REDIRECT_HTTP_AUTHORIZATION'])) {
4868
$headers['Authorization'] = $_SERVER['REDIRECT_HTTP_AUTHORIZATION'];
4969
} elseif (isset($_SERVER['PHP_AUTH_USER'])) {
5070
$basic_pass = $_SERVER['PHP_AUTH_PW'] ?? '';

0 commit comments

Comments
 (0)