From d43cabb7ecd4e5f0c729f282f46c2f466f79c3be Mon Sep 17 00:00:00 2001 From: huangzhhui Date: Thu, 29 Aug 2019 16:25:07 +0800 Subject: [PATCH] Optimized comment --- src/http-server/src/Contract/ResponseInterface.php | 5 ++++- src/http-server/src/Response.php | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/http-server/src/Contract/ResponseInterface.php b/src/http-server/src/Contract/ResponseInterface.php index 33ea6b293..98f3f88af 100644 --- a/src/http-server/src/Contract/ResponseInterface.php +++ b/src/http-server/src/Contract/ResponseInterface.php @@ -46,7 +46,10 @@ interface ResponseInterface public function redirect(string $toUrl, int $status = 302, string $schema = 'http'): PsrResponseInterface; /** - * Create a new file download response. + * Create a file download response. + * + * @param string $file The file path which want to send to client. + * @param string $name The alias name of the file that client receive. */ public function download(string $file, string $name = ''): PsrResponseInterface; } diff --git a/src/http-server/src/Response.php b/src/http-server/src/Response.php index 0c478f9f8..c895b33a0 100644 --- a/src/http-server/src/Response.php +++ b/src/http-server/src/Response.php @@ -115,6 +115,12 @@ class Response implements PsrResponseInterface, ResponseInterface return $this->getResponse()->withStatus($status)->withAddedHeader('Location', $toUrl); } + /** + * Create a file download response. + * + * @param string $file The file path which want to send to client. + * @param string $name The alias name of the file that client receive. + */ public function download(string $file, string $name = ''): PsrResponseInterface { $file = new \SplFileInfo($file); @@ -140,6 +146,7 @@ class Response implements PsrResponseInterface, ResponseInterface return $this->withHeader('content-description', 'File Transfer') ->withHeader('content-type', value(function () use ($file) { + $mineType = null; if (ApplicationContext::hasContainer()) { $guesser = ApplicationContext::getContainer()->get(MimeTypeExtensionGuesser::class); $mineType = $guesser->guessMimeType($file->getExtension());