Przeglądaj źródła

response->withFile add offset length parameters

walkor 5 lat temu
rodzic
commit
d96ec295da
1 zmienionych plików z 8 dodań i 5 usunięć
  1. 8 5
      Protocols/Http/Response.php

+ 8 - 5
Protocols/Http/Response.php

@@ -211,16 +211,18 @@ class Response
     }
 
     /**
-     * Set file.
+     * Send file.
      *
      * @param $file
+     * @param int $offset
+     * @param int $length
      * @return $this
      */
-    public function withFile($file) {
+    public function withFile($file, $offset = 0, $length = 0) {
         if (!\is_file($file)) {
             return $this->withStatus(404)->withBody('<h3>404 Not Found</h3>');
         }
-        $this->file = $file;
+        $this->file = array('file' => $file, 'offset' => $offset, 'length' => $length);
         return $this;
     }
 
@@ -253,8 +255,9 @@ class Response
      * @param $file
      * @return string
      */
-    protected function createHeadForFile($file)
+    protected function createHeadForFile($file_info)
     {
+        $file = $file_info['file'];
         $reason = $this->_reason ? $this->_reason : static::$_phrases[$this->_status];
         $head = "HTTP/{$this->_version} {$this->_status} $reason\r\n";
         $headers = $this->_header;
@@ -372,4 +375,4 @@ class Response
         }
     }
 }
-Response::init();
+Response::init();