src/Http/Message/ResponseDecorator.php
<?php
/**
* BitFrame Framework (https://www.bitframephp.com)
*
* @author Daniyal Hamid
* @copyright Copyright (c) 2017-2023 Daniyal Hamid (https://designcise.com)
* @license https://bitframephp.com/about/license MIT License
*/
declare(strict_types=1);
namespace BitFrame\Http\Message;
use Psr\Http\Message\{ResponseInterface, StreamInterface};
/**
* Http Response.
*/
class ResponseDecorator implements ResponseInterface
{
public function __construct(private ResponseInterface $response)
{
}
/**
* {@inheritdoc}
*/
public function withStatus($code, $reasonPhrase = ''): ResponseInterface|ResponseDecorator
{
$new = clone $this;
$new->setResponse($this->response->withStatus($code, $reasonPhrase));
return $new;
}
/**
* {@inheritdoc}
*/
public function withHeader($name, $value): ResponseInterface|ResponseDecorator
{
$new = clone $this;
$new->setResponse($this->response->withHeader($name, $value));
return $new;
}
/**
* {@inheritdoc}
*/
public function withAddedHeader($name, $value): ResponseInterface|ResponseDecorator
{
$new = clone $this;
$new->setResponse($this->response->withAddedHeader($name, $value));
return $new;
}
/**
* {@inheritdoc}
*/
public function withoutHeader($name): ResponseInterface|ResponseDecorator
{
$new = clone $this;
$new->setResponse($this->response->withoutHeader($name));
return $new;
}
/**
* {@inheritdoc}
*/
public function withProtocolVersion($version): ResponseInterface|ResponseDecorator
{
$new = clone $this;
$new->setResponse($this->response->withProtocolVersion($version));
return $new;
}
/**
* {@inheritdoc}
*/
public function withBody(StreamInterface $body): ResponseInterface|ResponseDecorator
{
$new = clone $this;
$new->setResponse($this->response->withBody($body));
return $new;
}
/**
* {@inheritdoc}
*/
public function hasHeader($name): bool
{
return $this->response->hasHeader($name);
}
/**
* {@inheritdoc}
*/
public function getProtocolVersion(): string
{
return $this->response->getProtocolVersion();
}
/**
* {@inheritdoc}
*/
public function getHeaders(): array
{
return $this->response->getHeaders();
}
/**
* {@inheritdoc}
*/
public function getHeader($name): array
{
return $this->response->getHeader($name);
}
/**
* {@inheritdoc}
*/
public function getHeaderLine($name): string
{
return $this->response->getHeaderLine($name);
}
/**
* {@inheritdoc}
*/
public function getBody(): StreamInterface
{
return $this->response->getBody();
}
/**
* {@inheritdoc}
*/
public function getStatusCode(): int
{
return $this->response->getStatusCode();
}
/**
* {@inheritdoc}
*/
public function getReasonPhrase(): string
{
return $this->response->getReasonPhrase();
}
public function setResponse(ResponseInterface $response): self
{
$this->response = $response;
return $this;
}
}