Переглянути джерело

Merge pull request #1050 from joanhey/response-property-promotion

Response construct use property promotion
walkor 1 рік тому
батько
коміт
fea0569418
2 змінених файлів з 7 додано та 32 видалено
  1. 1 1
      src/Protocols/Http.php
  2. 6 31
      src/Protocols/Http/Response.php

+ 1 - 1
src/Protocols/Http.php

@@ -248,7 +248,7 @@ class Http
             }
             $handler = fopen($file, 'r');
             if (false === $handler) {
-                $connection->close(new Response(403, null, '403 Forbidden'));
+                $connection->close(new Response(403, [], '403 Forbidden'));
                 return '';
             }
             $connection->send((string)$response, true);

+ 6 - 31
src/Protocols/Http/Response.php

@@ -39,19 +39,6 @@ use const FILE_SKIP_EMPTY_LINES;
  */
 class Response implements Stringable
 {
-    /**
-     * Header data.
-     *
-     * @var array
-     */
-    protected array $headers = [];
-
-    /**
-     * Http status.
-     *
-     * @var int
-     */
-    protected int $status;
 
     /**
      * Http reason.
@@ -68,13 +55,6 @@ class Response implements Stringable
     protected string $version = '1.1';
 
     /**
-     * Http body.
-     *
-     * @var string
-     */
-    protected string $body = '';
-
-    /**
      * Send file info
      *
      * @var ?array
@@ -177,20 +157,15 @@ class Response implements Stringable
     /**
      * Response constructor.
      *
-     * @param int $status
-     * @param array|null $headers
+     * @param int    $status
+     * @param array  $headers
      * @param string $body
      */
     public function __construct(
-        int     $status = 200,
-        ?array  $headers = [],
-        string  $body = ''
-    )
-    {
-        $this->status = $status;
-        $this->headers = $headers;
-        $this->body = $body;
-    }
+        protected int    $status = 200,
+        protected array  $headers = [],
+        protected string $body = ''
+    ) {}
 
     /**
      * Set header.