Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring envelopes #9

Open
wants to merge 1 commit into
base: release/1.0.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions src/Response/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\StreamInterface;

final class Response implements ResponseInterface
class Response implements ResponseInterface
{
private $statusCode;
private $reasonPhrase;
Expand All @@ -26,15 +26,15 @@ public function __construct(
/**
* @inheritdoc
*/
public function getProtocolVersion(): string
final public function getProtocolVersion(): string
{
return $this->message->getProtocolVersion();
}

/**
* @inheritdoc
*/
public function withProtocolVersion($version): self
final public function withProtocolVersion($version): self
{
return new self(
$this->message->withProtocolVersion($version),
Expand All @@ -46,39 +46,39 @@ public function withProtocolVersion($version): self
/**
* @inheritdoc
*/
public function getHeaders(): array
final public function getHeaders(): array
{
return $this->message->getHeaders();
}

/**
* @inheritdoc
*/
public function hasHeader($name): bool
final public function hasHeader($name): bool
{
return $this->message->hasHeader($name);
}

/**
* @inheritdoc
*/
public function getHeader($name): array
final public function getHeader($name): array
{
return $this->message->getHeader($name);
}

/**
* @inheritdoc
*/
public function getHeaderLine($name): string
final public function getHeaderLine($name): string
{
return $this->message->getHeaderLine($name);
}

/**
* @inheritdoc
*/
public function withHeader($name, $value): self
final public function withHeader($name, $value): self
{
return new self(
$this->message->withHeader($name, $value),
Expand All @@ -90,7 +90,7 @@ public function withHeader($name, $value): self
/**
* @inheritdoc
*/
public function withAddedHeader($name, $value): self
final public function withAddedHeader($name, $value): self
{
return new self(
$this->message->withAddedHeader($name, $value),
Expand All @@ -102,7 +102,7 @@ public function withAddedHeader($name, $value): self
/**
* @inheritdoc
*/
public function withoutHeader($name): self
final public function withoutHeader($name): self
{
return new self(
$this->message->withoutHeader($name),
Expand All @@ -114,31 +114,31 @@ public function withoutHeader($name): self
/**
* @inheritdoc
*/
public function getBody(): StreamInterface
final public function getBody(): StreamInterface
{
return $this->message->getBody();
}

/**
* @inheritdoc
*/
public function withBody(StreamInterface $body): self
final public function withBody(StreamInterface $body): self
{
return $this->message->withBody($body);
}

/**
* @inheritdoc
*/
public function getStatusCode(): int
final public function getStatusCode(): int
{
return $this->statusCode;
}

/**
* @inheritdoc
*/
public function withStatus($code, $reasonPhrase = ''): self
final public function withStatus($code, $reasonPhrase = ''): self
{
return new self(
$this->message,
Expand All @@ -150,7 +150,7 @@ public function withStatus($code, $reasonPhrase = ''): self
/**
* @inheritdoc
*/
public function getReasonPhrase(): string
final public function getReasonPhrase(): string
{
return $this->reasonPhrase;
}
Expand Down
132 changes: 2 additions & 130 deletions src/Response/TextResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,145 +3,17 @@

namespace Purist\Http\Response;

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\StreamInterface;
use Purist\Http\Header\Headers;
use Purist\Http\Message;
use Purist\Http\Stream\LazyReadOnlyTextStream;

final class TextResponse implements ResponseInterface
final class TextResponse extends Response
{
private $response;

public function __construct(string $text, int $statusCode = 200, Headers $headers = null)
{
$this->response = new Response(
parent::__construct(
new Message(new LazyReadOnlyTextStream($text), $headers),
$statusCode
);
}

/**
* @inheritdoc
*/
public function getProtocolVersion(): string
{
return $this->response->getProtocolVersion();
}

/**
* @inheritdoc
*/
public function withProtocolVersion($version): self
{
$response = clone $this;
$response->response = $this->response->withProtocolVersion($version);
return $response;
}

/**
* @inheritdoc
*/
public function getHeaders(): array
{
return $this->response->getHeaders();
}

/**
* @inheritdoc
*/
public function hasHeader($name): bool
{
return $this->response->hasHeader($name);
}

/**
* @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 withHeader($name, $value): self
{
$response = clone $this;
$response->response = $this->response->withHeader($name, $value);
return $response;
}

/**
* @inheritdoc
*/
public function withAddedHeader($name, $value): self
{
$response = clone $this;
$response->response = $this->response->withAddedHeader($name, $value);
return $response;
}

/**
* @inheritdoc
*/
public function withoutHeader($name): self
{
$response = clone $this;
$response->response = $this->response->withoutHeader($name);
return $response;
}

/**
* @inheritdoc
*/
public function getBody(): StreamInterface
{
return $this->response->getBody();
}

/**
* @inheritdoc
*/
public function withBody(StreamInterface $body)
{
$response = clone $this;
$response->response = $this->response->withBody($body);
return $response;
}

/**
* @inheritdoc
*/
public function getStatusCode(): int
{
return $this->response->getStatusCode();
}

/**
* @inheritdoc
*/
public function withStatus($code, $reasonPhrase = '')
{
$response = clone $this;
$response->response = $this->response->withStatus($code, $reasonPhrase);
return $response;
}

/**
* @inheritdoc
*/
public function getReasonPhrase(): string
{
return $this->response->getReasonPhrase();
}
}