setFile() public method

Sets the file to stream.
public setFile ( SplFileInfo | string $file, string $contentDisposition = null, boolean $autoEtag = false, boolean $autoLastModified = true ) : BinaryFileResponse
$file SplFileInfo | string The file to stream
$contentDisposition string
$autoEtag boolean
$autoLastModified boolean
return BinaryFileResponse
 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;
 }
Ejemplo n.º 2
0
 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;
 }