Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add new optional fileNameFallBack argument #338

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Snappy/Response/JpegResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

class JpegResponse extends SnappyResponse
{
public function __construct($content, $fileName = 'output.jpg', $contentType = 'image/jpg', $contentDisposition = 'inline', $status = 200, $headers = [])
public function __construct($content, $fileName = 'output.jpg', $contentType = 'image/jpg', $contentDisposition = 'inline', $status = 200, $headers = [], $fileNameFallBack = '')
{
parent::__construct($content, $fileName, $contentType, $contentDisposition, $status, $headers);
parent::__construct($content, $fileName, $contentType, $contentDisposition, $status, $headers, $fileNameFallBack);
}
}
4 changes: 2 additions & 2 deletions src/Snappy/Response/PdfResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

class PdfResponse extends SnappyResponse
{
public function __construct($content, $fileName = 'output.pdf', $contentType = 'application/pdf', $contentDisposition = 'attachment', $status = 200, $headers = [])
public function __construct($content, $fileName = 'output.pdf', $contentType = 'application/pdf', $contentDisposition = 'attachment', $status = 200, $headers = [], $fileNameFallBack = '')
{
parent::__construct($content, $fileName, $contentType, $contentDisposition, $status, $headers);
parent::__construct($content, $fileName, $contentType, $contentDisposition, $status, $headers, $fileNameFallBack);
}
}
4 changes: 2 additions & 2 deletions src/Snappy/Response/SnappyResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class SnappyResponse extends Base
{
public function __construct($content, $fileName, $contentType, $contentDisposition = 'attachment', $status = 200, $headers = [])
public function __construct($content, $fileName, $contentType, $contentDisposition = 'attachment', $status = 200, $headers = [], $fileNameFallBack = '')
{
$contentDispositionDirectives = [ResponseHeaderBag::DISPOSITION_INLINE, ResponseHeaderBag::DISPOSITION_ATTACHMENT];
if (!in_array($contentDisposition, $contentDispositionDirectives)) {
Expand All @@ -16,6 +16,6 @@ public function __construct($content, $fileName, $contentType, $contentDispositi

parent::__construct($content, $status, $headers);
$this->headers->add(['Content-Type' => $contentType]);
$this->headers->add(['Content-Disposition' => $this->headers->makeDisposition($contentDisposition, $fileName)]);
$this->headers->add(['Content-Disposition' => $this->headers->makeDisposition($contentDisposition, $fileName, $fileNameFallBack)]);
}
}
6 changes: 6 additions & 0 deletions tests/Snappy/Response/JpegResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,10 @@ public function testSetDifferentFileName(): void

$this->assertSame($fileName, $matches[1]);
}

public function testSpecialCharacters(): void
{
$response = new JpegResponse('', 'Ä.jpg', 'image/jpg', fileNameFallBack: 'thefilenamefallback.jpg');
$this->assertSame('inline; filename=thefilenamefallback.jpg; filename*=utf-8\'\'%C3%84.jpg', str_replace('"', '', $response->headers->get('Content-Disposition')));
}
}
6 changes: 6 additions & 0 deletions tests/Snappy/Response/PdfResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,10 @@ public function testSetDifferentFileName(): void

$this->assertSame($fileName, $matches[1]);
}

public function testSpecialCharacters(): void
{
$response = new PdfResponse('', 'Ä.jpg', 'image/jpg', fileNameFallBack: 'thefilenamefallback.jpg');
$this->assertSame('attachment; filename=thefilenamefallback.jpg; filename*=utf-8\'\'%C3%84.jpg', str_replace('"', '', $response->headers->get('Content-Disposition')));
}
}
Loading