sunrise-php /
http-message
| 1 | <?php declare(strict_types=1); |
||
| 2 | |||
| 3 | /** |
||
| 4 | * It's free open-source software released under the MIT License. |
||
| 5 | * |
||
| 6 | * @author Anatoly Nekhay <[email protected]> |
||
| 7 | * @copyright Copyright (c) 2018, Anatoly Nekhay |
||
| 8 | * @license https://github.com/sunrise-php/http-message/blob/master/LICENSE |
||
| 9 | * @link https://github.com/sunrise-php/http-message |
||
| 10 | */ |
||
| 11 | |||
| 12 | namespace Sunrise\Http\Message; |
||
| 13 | |||
| 14 | use Psr\Http\Message\ServerRequestFactoryInterface; |
||
| 15 | use Psr\Http\Message\ServerRequestInterface; |
||
| 16 | use Sunrise\Http\Message\Stream\PhpInputStream; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @psalm-suppress ClassMustBeFinal |
||
| 20 | */ |
||
| 21 | class ServerRequestFactory implements ServerRequestFactoryInterface |
||
| 22 | { |
||
| 23 | /** |
||
| 24 | * @param array<array-key, mixed>|null $serverParams |
||
|
0 ignored issues
–
show
Documentation
Bug
introduced
by
Loading history...
|
|||
| 25 | * @param array<array-key, mixed>|null $queryParams |
||
| 26 | * @param array<array-key, mixed>|null $cookieParams |
||
| 27 | * @param array<array-key, mixed>|null $uploadedFiles |
||
| 28 | * @param array<array-key, mixed>|null $parsedBody |
||
| 29 | * |
||
| 30 | * @link http://php.net/manual/en/language.variables.superglobals.php |
||
| 31 | * @link https://www.php-fig.org/psr/psr-15/meta/ |
||
| 32 | */ |
||
| 33 | 40 | public static function fromGlobals( |
|
| 34 | ?array $serverParams = null, |
||
| 35 | ?array $queryParams = null, |
||
| 36 | ?array $cookieParams = null, |
||
| 37 | ?array $uploadedFiles = null, |
||
| 38 | ?array $parsedBody = null |
||
| 39 | ): ServerRequestInterface { |
||
| 40 | 40 | $serverParams ??= $_SERVER; |
|
| 41 | 40 | $queryParams ??= $_GET; |
|
| 42 | 40 | $cookieParams ??= $_COOKIE; |
|
| 43 | 40 | $uploadedFiles ??= $_FILES; |
|
| 44 | 40 | $parsedBody ??= $_POST; |
|
| 45 | |||
| 46 | 40 | return new ServerRequest( |
|
| 47 | 40 | server_request_protocol_version($serverParams), |
|
| 48 | 40 | server_request_method($serverParams), |
|
| 49 | 40 | server_request_uri($serverParams), |
|
| 50 | 40 | server_request_headers($serverParams), |
|
| 51 | 40 | new PhpInputStream(), |
|
| 52 | 40 | $serverParams, |
|
| 53 | 40 | $queryParams, |
|
| 54 | 40 | $cookieParams, |
|
| 55 | 40 | server_request_files($uploadedFiles), |
|
| 56 | 40 | $parsedBody |
|
| 57 | 40 | ); |
|
| 58 | } |
||
| 59 | |||
| 60 | /** |
||
| 61 | * {@inheritDoc} |
||
| 62 | * |
||
| 63 | * @param mixed $uri |
||
| 64 | * @param array<array-key, mixed> $serverParams |
||
|
0 ignored issues
–
show
|
|||
| 65 | */ |
||
| 66 | 19 | public function createServerRequest(string $method, $uri, array $serverParams = []): ServerRequestInterface |
|
| 67 | { |
||
| 68 | 19 | return new ServerRequest( |
|
| 69 | 19 | server_request_protocol_version($serverParams), |
|
| 70 | 19 | $method, |
|
| 71 | 19 | $uri, |
|
| 72 | 19 | server_request_headers($serverParams), |
|
| 73 | 19 | null, // body |
|
| 74 | 19 | $serverParams |
|
| 75 | 19 | ); |
|
| 76 | } |
||
| 77 | } |
||
| 78 |