X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModule%2FResponse.php;h=d38b330bb3bd57fa1a6c337354d05041b50b18bc;hb=fd5914011cb5c67b827886a5db0e7760a307ad1d;hp=29df82c04432cf2f1398a9cac023a5bcf82f015d;hpb=ae24bf8d5403743dfb4f4400e436ddf97499825e;p=friendica.git diff --git a/src/Module/Response.php b/src/Module/Response.php index 29df82c044..d38b330bb3 100644 --- a/src/Module/Response.php +++ b/src/Module/Response.php @@ -1,4 +1,23 @@ . + * + */ namespace Friendica\Module; @@ -19,7 +38,11 @@ class Response implements ICanCreateResponses /** * @var string */ - protected $type = ICanCreateResponses::TYPE_HTML; + protected $type = self::TYPE_HTML; + + protected $status = 200; + + protected $reason = null; /** * {@inheritDoc} @@ -68,25 +91,42 @@ class Response implements ICanCreateResponses */ public function setType(string $type, ?string $content_type = null): void { - if (!in_array($type, ICanCreateResponses::ALLOWED_TYPES)) { + if (!in_array($type, static::ALLOWED_TYPES)) { throw new InternalServerErrorException('wrong type'); } switch ($type) { + case static::TYPE_HTML: + $content_type = $content_type ?? 'text/html; charset=utf-8'; + break; case static::TYPE_JSON: $content_type = $content_type ?? 'application/json'; break; case static::TYPE_XML: $content_type = $content_type ?? 'text/xml'; break; + case static::TYPE_RSS: + $content_type = $content_type ?? 'application/rss+xml'; + break; + case static::TYPE_ATOM: + $content_type = $content_type ?? 'application/atom+xml'; + break; } - $this->setHeader($content_type, 'Content-type'); $this->type = $type; } + /** + * {@inheritDoc} + */ + public function setStatus(int $status = 200, ?string $reason = null): void + { + $this->status = $status; + $this->reason = $reason; + } + /** * {@inheritDoc} */ @@ -101,8 +141,8 @@ class Response implements ICanCreateResponses public function generate(): ResponseInterface { // Setting the response type as an X-header for direct usage - $this->headers['X-RESPONSE-TYPE'] = $this->type; + $this->headers[static::X_HEADER] = $this->type; - return new \GuzzleHttp\Psr7\Response(200, $this->headers, $this->content); + return new \GuzzleHttp\Psr7\Response($this->status, $this->headers, $this->content, '1.1', $this->reason); } }