Lines
95.65%
22 / 23
Functions and Methods
0.00%
0 / 1
Classes and Traits
0.00%
0 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Request | 95.65% | 22 / 23 | 0.00% | 0 / 1 | 9 | 0.00% | 0 / 1 | |||
| __construct | 95.65% | 22 / 23 | 0.00% | 0 / 1 | 9 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | namespace BO\Zmsclient\Psr7; | |
| 4 | ||
| 5 | use Slim\Psr7\Interfaces\HeadersInterface; | |
| 6 | use Slim\Psr7\Headers; | |
| 7 | use Psr\Http\Message\UriInterface; | |
| 8 | use Psr\Http\Message\StreamInterface; | |
| 9 | use BO\Slim\Request as SlimRequest; | |
| 10 | ||
| 11 | /** | |
| 12 | * Layer to change PSR7 implementation if necessary | |
| 13 | * @SuppressWarnings(Superglobals) | |
| 14 | * @psalm-suppress PropertyNotSetInConstructor | |
| 15 | */ | |
| 16 | class Request extends SlimRequest implements \Psr\Http\Message\ServerRequestInterface | |
| 17 | { | |
| 18 | public function __construct( | |
| 19 | ?string $method = null, | |
| 20 | mixed $uri = null, | |
| 21 | mixed $body = 'php://memory', | |
| 22 | mixed $headers = array() | |
| 23 | ) { | |
| 24 | $cookies = []; | |
| 25 | $serverParams = $_SERVER; | |
| 26 | $uploadedFiles = []; | |
| 27 | if (!$uri instanceof UriInterface) { | |
| 28 | $uri = new Uri(is_string($uri) ? $uri : ''); | |
| 29 | } | |
| 30 | if (!$headers instanceof HeadersInterface) { | |
| 31 | $headers = new Headers(is_array($headers) ? $headers : []); | |
| 32 | } | |
| 33 | if (!$body instanceof StreamInterface) { | |
| 34 | if (!is_resource($body)) { | |
| 35 | $opened = fopen(is_string($body) ? $body : 'php://memory', 'w+b'); | |
| 36 | if ($opened === false) { | |
| 37 | throw new \RuntimeException('Unable to open request body stream'); | |
| 38 | } | |
| 39 | $body = $opened; | |
| 40 | } | |
| 41 | $body = new Stream($body); | |
| 42 | } | |
| 43 | parent::__construct( | |
| 44 | $method ?? 'GET', | |
| 45 | $uri, | |
| 46 | $headers, | |
| 47 | $cookies, | |
| 48 | $serverParams, | |
| 49 | $body, | |
| 50 | $uploadedFiles | |
| 51 | ); | |
| 52 | } | |
| 53 | } |