Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 20 |
|
0.00% |
0 / 18 |
CRAP | |
0.00% |
0 / 1 |
| Request | |
0.00% |
0 / 20 |
|
0.00% |
0 / 18 |
380 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| getProtocolVersion | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| withProtocolVersion | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getHeaders | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| hasHeader | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getHeader | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getHeaderLine | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| withHeader | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| withAddedHeader | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| withoutHeader | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getBody | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| withBody | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getRequestTarget | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| withRequestTarget | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getMethod | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| withMethod | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getUri | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| withUri | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace pvc\http\psr7; |
| 4 | |
| 5 | use Psr\Http\Message\MessageInterface; |
| 6 | use Psr\Http\Message\RequestInterface; |
| 7 | use Psr\Http\Message\StreamInterface; |
| 8 | use Psr\Http\Message\UriInterface; |
| 9 | |
| 10 | use GuzzleHttp\Psr7\Request as GuzzleRequest; |
| 11 | use pvc\http\err\InvalidHttpVerbException; |
| 12 | |
| 13 | class Request implements RequestInterface |
| 14 | { |
| 15 | protected array $httpVerbs |
| 16 | = [ |
| 17 | 'GET', |
| 18 | 'POST', |
| 19 | 'PUT', |
| 20 | 'PATCH', |
| 21 | 'DELETE', |
| 22 | 'HEAD', |
| 23 | 'OPTIONS', |
| 24 | 'CONNECT', |
| 25 | 'TRACE' |
| 26 | ]; |
| 27 | |
| 28 | protected GuzzleRequest $guzzleRequest; |
| 29 | |
| 30 | public function __construct(string $method, UriInterface $uri) |
| 31 | { |
| 32 | /** |
| 33 | * guzzle allows customized (free form) verbs, pvc does not. |
| 34 | */ |
| 35 | if (!in_array($method, $this->httpVerbs)) { |
| 36 | throw new InvalidHttpVerbException($method); |
| 37 | } |
| 38 | |
| 39 | $this->guzzleRequest = new GuzzleRequest($method, $uri->__toString()); |
| 40 | } |
| 41 | |
| 42 | public function getProtocolVersion(): string |
| 43 | { |
| 44 | return $this->guzzleRequest->getProtocolVersion(); |
| 45 | } |
| 46 | |
| 47 | public function withProtocolVersion(string $version): MessageInterface |
| 48 | { |
| 49 | return $this->guzzleRequest->withProtocolVersion($version); |
| 50 | } |
| 51 | |
| 52 | public function getHeaders(): array |
| 53 | { |
| 54 | return $this->guzzleRequest->getHeaders(); |
| 55 | } |
| 56 | |
| 57 | public function hasHeader(string $name): bool |
| 58 | { |
| 59 | return $this->guzzleRequest->hasHeader($name); |
| 60 | } |
| 61 | |
| 62 | public function getHeader(string $name): array |
| 63 | { |
| 64 | return $this->guzzleRequest->getHeader($name); |
| 65 | } |
| 66 | |
| 67 | public function getHeaderLine(string $name): string |
| 68 | { |
| 69 | return $this->guzzleRequest->getHeaderLine($name); |
| 70 | } |
| 71 | |
| 72 | public function withHeader(string $name, $value): MessageInterface |
| 73 | { |
| 74 | return $this->guzzleRequest->withHeader($name, $value); |
| 75 | } |
| 76 | |
| 77 | public function withAddedHeader(string $name, $value): MessageInterface |
| 78 | { |
| 79 | return $this->guzzleRequest->withAddedHeader($name, $value); |
| 80 | } |
| 81 | |
| 82 | public function withoutHeader(string $name): MessageInterface |
| 83 | { |
| 84 | return $this->guzzleRequest->withoutHeader($name); |
| 85 | } |
| 86 | |
| 87 | public function getBody(): StreamInterface |
| 88 | { |
| 89 | return $this->guzzleRequest->getBody(); |
| 90 | } |
| 91 | |
| 92 | public function withBody(StreamInterface $body): MessageInterface |
| 93 | { |
| 94 | return $this->guzzleRequest->withBody($body); |
| 95 | } |
| 96 | |
| 97 | public function getRequestTarget(): string |
| 98 | { |
| 99 | return $this->guzzleRequest->getRequestTarget(); |
| 100 | } |
| 101 | |
| 102 | public function withRequestTarget(string $requestTarget): RequestInterface |
| 103 | { |
| 104 | return $this->guzzleRequest->withRequestTarget($requestTarget); |
| 105 | } |
| 106 | |
| 107 | public function getMethod(): string |
| 108 | { |
| 109 | return $this->guzzleRequest->getMethod(); |
| 110 | } |
| 111 | |
| 112 | public function withMethod(string $method): RequestInterface |
| 113 | { |
| 114 | return $this->guzzleRequest->withMethod($method); |
| 115 | } |
| 116 | |
| 117 | public function getUri(): UriInterface |
| 118 | { |
| 119 | return $this->guzzleRequest->getUri(); |
| 120 | } |
| 121 | |
| 122 | public function withUri( |
| 123 | UriInterface $uri, |
| 124 | bool $preserveHost = false |
| 125 | ): RequestInterface { |
| 126 | return $this->guzzleRequest->withUri($uri, $preserveHost); |
| 127 | } |
| 128 | } |