From 60685547b60726d141a5a3ad70be47a99b4ad166 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sat, 2 Feb 2019 23:56:43 +0100 Subject: [PATCH] Add downloadable+array query data --- Message/Http/Header.php | 20 ++++++++++++++++++++ Message/Http/Request.php | 6 +++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/Message/Http/Header.php b/Message/Http/Header.php index 23b0b3307..d539b67e6 100644 --- a/Message/Http/Header.php +++ b/Message/Http/Header.php @@ -15,6 +15,7 @@ declare(strict_types=1); namespace phpOMS\Message\Http; use phpOMS\Message\HeaderAbstract; +use phpOMS\System\MimeType; /** * Response class. @@ -86,6 +87,25 @@ final class Header extends HeaderAbstract return true; } + /** + * Set header as downloadable + * + * @param string $name Download name + * @param string $type Download file type + * + * @return void + * + * @since 1.0.0 + */ + public function setDownloadable(string $name, string $type) : void + { + $this->set('Content-Type', MimeType::M_BIN, true); + $this->set('Content-Transfer-Encoding', 'Binary', true); + $this->set( + 'Content-disposition', 'attachment; filename="' . $name . '.' . $type . '"' + , true); + } + /** * Is security header. * diff --git a/Message/Http/Request.php b/Message/Http/Request.php index 5f6e44db0..b722dc646 100644 --- a/Message/Http/Request.php +++ b/Message/Http/Request.php @@ -212,7 +212,11 @@ final class Request extends RequestAbstract UriFactory::setQuery('/lang', $this->header->getL11n()->getLanguage()); foreach ($this->data as $key => $value) { - UriFactory::setQuery('?' . $key, $value); + if (\is_array($value)) { + UriFactory::setQuery('?' . $key, \implode(',', $value)); + } else { + UriFactory::setQuery('?' . $key, $value); + } } }