statusCode = $statusCode; return $this; } public function withJsonHeader(): self { return $this->addHeader('Content-Type', 'application/json'); } public function withExpiration(int $timestamp): self { return $this->addHeader('Expires', gmdate('D, d M Y H:i:s \G\M\T', $timestamp)); } public function addHeader(string $name, string $value): self { $this->headers[$name] = $value; return $this; } /** * @param string|array|JsonSerializable|null|resource|StreamInterface $body * * @return $this */ public function withBody($body): self { $this->body = stream_for(is_array($body) || $body instanceof JsonSerializable ? json_encode($body) : $body); return $this; } public function format(ResponseInterface $response): ResponseInterface { if ($this->body) { $response = $response->withBody($this->body); } if ($this->statusCode) { $response = $response->withStatus($this->statusCode); } foreach ($this->headers as $headerName => $headerValue) { $response = $response->withHeader($headerName, $headerValue); } return $response; } }