|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace SimpleAsFuck\ApiToolkit\Data\Common; |
| 6 | + |
| 7 | +use Psr\Http\Message\ResponseInterface; |
| 8 | +use Psr\Http\Message\StreamInterface; |
| 9 | + |
| 10 | +abstract readonly class Response implements ResponseInterface |
| 11 | +{ |
| 12 | + public function __construct( |
| 13 | + private ResponseInterface $response, |
| 14 | + ) { |
| 15 | + } |
| 16 | + |
| 17 | + public function withProtocolVersion(string $version): static |
| 18 | + { |
| 19 | + return $this->clone($this->response->withProtocolVersion($version)); |
| 20 | + } |
| 21 | + |
| 22 | + /** |
| 23 | + * @param string|array<string> $value |
| 24 | + */ |
| 25 | + public function withHeader(string $name, $value): static |
| 26 | + { |
| 27 | + return $this->clone($this->response->withHeader($name, $value)); |
| 28 | + } |
| 29 | + |
| 30 | + /** |
| 31 | + * @param string $name |
| 32 | + * @param string|array<string> $value |
| 33 | + */ |
| 34 | + public function withAddedHeader(string $name, $value): static |
| 35 | + { |
| 36 | + return $this->clone($this->response->withAddedHeader($name, $value)); |
| 37 | + } |
| 38 | + |
| 39 | + public function withoutHeader(string $name): static |
| 40 | + { |
| 41 | + return $this->clone($this->response->withoutHeader($name)); |
| 42 | + } |
| 43 | + |
| 44 | + public function withBody(StreamInterface $body): static |
| 45 | + { |
| 46 | + return $this->clone($this->response->withBody($body)); |
| 47 | + } |
| 48 | + |
| 49 | + public function withStatus(int $code, string $reasonPhrase = ''): static |
| 50 | + { |
| 51 | + return $this->clone($this->response->withStatus($code, $reasonPhrase)); |
| 52 | + } |
| 53 | + |
| 54 | + public function getProtocolVersion(): string |
| 55 | + { |
| 56 | + return $this->response->getProtocolVersion(); |
| 57 | + } |
| 58 | + |
| 59 | + /** |
| 60 | + * @return array<string, array<string>> |
| 61 | + */ |
| 62 | + public function getHeaders(): array |
| 63 | + { |
| 64 | + /** @var array<string, array<string>> */ |
| 65 | + return $this->response->getHeaders(); |
| 66 | + } |
| 67 | + |
| 68 | + public function hasHeader(string $name): bool |
| 69 | + { |
| 70 | + return $this->response->hasHeader($name); |
| 71 | + } |
| 72 | + |
| 73 | + /** |
| 74 | + * @return array<string> |
| 75 | + */ |
| 76 | + public function getHeader(string $name): array |
| 77 | + { |
| 78 | + return $this->response->getHeader($name); |
| 79 | + } |
| 80 | + |
| 81 | + public function getHeaderLine(string $name): string |
| 82 | + { |
| 83 | + return $this->response->getHeaderLine($name); |
| 84 | + } |
| 85 | + |
| 86 | + public function getBody(): StreamInterface |
| 87 | + { |
| 88 | + return $this->response->getBody(); |
| 89 | + } |
| 90 | + |
| 91 | + public function getStatusCode(): int |
| 92 | + { |
| 93 | + return $this->response->getStatusCode(); |
| 94 | + } |
| 95 | + |
| 96 | + public function getReasonPhrase(): string |
| 97 | + { |
| 98 | + return $this->response->getReasonPhrase(); |
| 99 | + } |
| 100 | + |
| 101 | + abstract protected function clone(ResponseInterface $response): static; |
| 102 | +} |
0 commit comments