Last active
January 27, 2016 15:21
-
-
Save xphere/9874b52265ac51b6eaa6 to your computer and use it in GitHub Desktop.
Some controller helpers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Symfony\Component\HttpFoundation\Response; | |
use Symfony\Component\HttpFoundation\ResponseHeaderBag; | |
trait MakeDownloadable | |
{ | |
/** | |
* @param Response $response | |
* @param string $filename | |
* @param string $contentType | |
* | |
* @return Response | |
*/ | |
private function makeDownloadable(Response $response, $filename, $contentType) | |
{ | |
$disposition = $response->headers->makeDisposition( | |
ResponseHeaderBag::DISPOSITION_ATTACHMENT, | |
$filename | |
); | |
$response->headers->add([ | |
'Content-Type' => $contentType, | |
'Content-Disposition' => $disposition, | |
]); | |
return $response; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment