| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Nyholm\Psr7Server; |
| 6 |
|
| 7 |
use Psr\Http\Message\ServerRequestInterface; |
| 8 |
use Psr\Http\Message\StreamInterface; |
| 9 |
|
| 10 |
/** |
| 11 |
* @author Tobias Nyholm <[email protected]> |
| 12 |
* @author Martijn van der Ven <[email protected]> |
| 13 |
*/ |
| 14 |
interface ServerRequestCreatorInterface |
| 15 |
{ |
| 16 |
/** |
| 17 |
* Create a new server request from the current environment variables. |
| 18 |
* Defaults to a GET request to minimise the risk of an \InvalidArgumentException. |
| 19 |
* Includes the current request headers as supplied by the server through `getallheaders()`. |
| 20 |
* If `getallheaders()` is unavailable on the current server it will fallback to its own `getHeadersFromServer()` method. |
| 21 |
* Defaults to php://input for the request body. |
| 22 |
* |
| 23 |
* @throws \InvalidArgumentException if no valid method or URI can be determined |
| 24 |
*/ |
| 25 |
public function fromGlobals(): ServerRequestInterface; |
| 26 |
|
| 27 |
/** |
| 28 |
* Create a new server request from a set of arrays. |
| 29 |
* |
| 30 |
* @param array $server typically $_SERVER or similar structure |
| 31 |
* @param array $headers typically the output of getallheaders() or similar structure |
| 32 |
* @param array $cookie typically $_COOKIE or similar structure |
| 33 |
* @param array $get typically $_GET or similar structure |
| 34 |
* @param array|null $post typically $_POST or similar structure, represents parsed request body |
| 35 |
* @param array $files typically $_FILES or similar structure |
| 36 |
* @param StreamInterface|resource|string|null $body Typically stdIn |
| 37 |
* |
| 38 |
* @throws \InvalidArgumentException if no valid method or URI can be determined |
| 39 |
*/ |
| 40 |
public function fromArrays( |
| 41 |
array $server, |
| 42 |
array $headers = [], |
| 43 |
array $cookie = [], |
| 44 |
array $get = [], |
| 45 |
?array $post = null, |
| 46 |
array $files = [], |
| 47 |
$body = null |
| 48 |
): ServerRequestInterface; |
| 49 |
|
| 50 |
/** |
| 51 |
* Get parsed headers from ($_SERVER) array. |
| 52 |
* |
| 53 |
* @param array $server typically $_SERVER or similar structure |
| 54 |
*/ |
| 55 |
public static function getHeadersFromServer(array $server): array; |
| 56 |
} |
| 57 |
|