]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/Response.php
Changes after review
[friendica.git] / src / Module / Response.php
index dc11c9908df0c34c5a4fd10c167c7e92d90cef70..78db953bb4a3b7ca24dc501fc389b1ced762eb70 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2022, the Friendica project
+ * @copyright Copyright (C) 2010-2023, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -40,6 +40,10 @@ class Response implements ICanCreateResponses
         */
        protected $type = self::TYPE_HTML;
 
+       protected $status = 200;
+
+       protected $reason = null;
+
        /**
         * {@inheritDoc}
         */
@@ -85,13 +89,16 @@ class Response implements ICanCreateResponses
        /**
         * {@inheritDoc}
         */
-       public function setType(string $type, ?string $content_type = null): void
+       public function setType(string $type = Response::TYPE_HTML, ?string $content_type = null): void
        {
                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;
@@ -111,6 +118,15 @@ class Response implements ICanCreateResponses
                $this->type = $type;
        }
 
+       /**
+        * {@inheritDoc}
+        */
+       public function setStatus(int $status = 200, ?string $reason = null): void
+       {
+               $this->status = $status;
+               $this->reason = $reason;
+       }
+
        /**
         * {@inheritDoc}
         */
@@ -127,6 +143,6 @@ class Response implements ICanCreateResponses
                // Setting the response type as an X-header for direct usage
                $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);
        }
 }