From fe36bc9ecd3b834eb071bd18dd31863f5ccc2807 Mon Sep 17 00:00:00 2001 From: Klimov Paul Date: Tue, 19 Aug 2014 16:31:42 +0300 Subject: [PATCH] `options` parameter extracted at `yii\web\Response::xSendFile()` --- framework/web/Response.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/framework/web/Response.php b/framework/web/Response.php index 91a254a054..2e8a279062 100644 --- a/framework/web/Response.php +++ b/framework/web/Response.php @@ -632,11 +632,12 @@ class Response extends \yii\base\Response * @param string $filePath file name with full path * @param string $attachmentName file name shown to the user. If null, it will be determined from `$filePath`. * @param string $mimeType the MIME type of the file. If null, it will be determined based on `$filePath`. - * @param boolean $forceDownload whether the file will be downloaded or shown inline. - * @param string $xHeader the name of the x-sendfile header. + * @param array $options additional options. Valid options are: + * - forceDownload: boolean, whether the file will be downloaded or shown inline. Defaults to true. + * - xHeader: string, the name of the x-sendfile header. Defaults to "X-Sendfile". * @return static the response object itself */ - public function xSendFile($filePath, $attachmentName = null, $mimeType = null, $forceDownload = true, $xHeader = 'X-Sendfile') + public function xSendFile($filePath, $attachmentName = null, $mimeType = null, $options = []) { if ($mimeType === null && ($mimeType = FileHelper::getMimeTypeByExtension($filePath)) === null) { $mimeType = 'application/octet-stream'; @@ -644,7 +645,16 @@ class Response extends \yii\base\Response if ($attachmentName === null) { $attachmentName = basename($filePath); } - $disposition = $forceDownload ? 'attachment' : 'inline'; + if (isset($options['xHeader'])) { + $xHeader = $options['xHeader']; + } else { + $xHeader = 'X-Sendfile'; + } + if (!isset($options['forceDownload']) || $options['forceDownload']) { + $disposition = 'attachment'; + } else { + $disposition = 'inline'; + } $this->getHeaders() ->setDefault($xHeader, $filePath)