You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.9 KiB
62 lines
1.9 KiB
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace IOcornerstone\Framework\Http;
|
|
|
|
use Psr\Http\Message\ResponseInterface;
|
|
|
|
final class Response implements ResponseInterface
|
|
{
|
|
public function __construct(
|
|
private int $status = 200,
|
|
private array $headers = [],
|
|
private Stream $body = new Stream(STDIN),
|
|
private string $protocol = '1.1'
|
|
) {}
|
|
|
|
public function getStatusCode(): int { return $this->status; }
|
|
public function withStatus($code, $reasonPhrase = ''): self {
|
|
$clone = clone $this;
|
|
$clone->status = $code;
|
|
return $clone;
|
|
}
|
|
|
|
public function getBody(): Stream { return $this->body; }
|
|
public function withBody(\Psr\Http\Message\StreamInterface $body): self {
|
|
$clone = clone $this;
|
|
$clone->body = $body;
|
|
return $clone;
|
|
}
|
|
|
|
public function getHeaders(): array { return $this->headers; }
|
|
public function hasHeader($name): bool { return isset($this->headers[strtolower($name)]); }
|
|
public function getHeader($name): array { return $this->headers[strtolower($name)] ?? []; }
|
|
public function getHeaderLine($name): string { return implode(',', $this->getHeader($name)); }
|
|
|
|
public function withHeader($name, $value): self {
|
|
$clone = clone $this;
|
|
$clone->headers[strtolower($name)] = (array)$value;
|
|
return $clone;
|
|
}
|
|
|
|
public function withAddedHeader($name, $value): self {
|
|
$clone = clone $this;
|
|
$clone->headers[strtolower($name)][] = $value;
|
|
return $clone;
|
|
}
|
|
|
|
public function withoutHeader($name): self {
|
|
$clone = clone $this;
|
|
unset($clone->headers[strtolower($name)]);
|
|
return $clone;
|
|
}
|
|
|
|
public function getProtocolVersion(): string { return $this->protocol; }
|
|
public function withProtocolVersion($version): self {
|
|
$clone = clone $this;
|
|
$clone->protocol = $version;
|
|
return $clone;
|
|
}
|
|
|
|
public function getReasonPhrase(): string { return ''; }
|
|
}
|
|
|