Sets the file to stream.
public setFile ( SplFileInfo | string $file, string $contentDisposition = null, boolean $autoEtag = false, boolean $autoLastModified = true ) : |
||
$file | SplFileInfo | string | The file to stream |
$contentDisposition | string | |
$autoEtag | boolean | |
$autoLastModified | boolean | |
return |
public function setFile($file, $contentDisposition = null, $autoEtag = false, $autoLastModified = true) { parent::setFile($file, $contentDisposition, $autoEtag, $autoLastModified); $this->prepend = 'hljs.registerLanguage("' . $this->file->getBasename('.' . $this->file->getExtension()) . '", '; $this->append = ');'; return $this; }
public function render(Request $request, Response $response, array $args) { $item = new Item($args['id']); $size = isset($args['size']) ? $args['size'] : 'o'; $version = isset($args['version']) ? $args['version'] : null; $cacheFile = $item->getCachePath($size, $version); $fileResponse = new BinaryFileResponse($cacheFile); $fileResponse->headers->set('Content-Type', 'image/png'); $fileResponse->setFile($cacheFile); $fileResponse->setContentDisposition(ResponseHeaderBag::DISPOSITION_INLINE, $item->getTitle() . '.png'); return $fileResponse; }