Exemple #1
0
 protected function buildResponseFromResponseBag(ResponseBag $responseBag)
 {
     $result = $responseBag->getResult();
     $resultCode = $responseBag->getResultCode();
     $headers = $responseBag->getHeaders();
     $type = $responseBag->getType();
     if ($type === ResponseBag::TYPE_DEFAULT) {
         return new Response($result, $resultCode, $headers);
     }
     if ($type === ResponseBag::TYPE_STREAMED) {
         $callback = $responseBag->getCallback();
         if (null === $callback) {
             throw new \Exception('Streamed response need callback');
         }
         return new StreamedResponse($callback, $resultCode, $headers);
     }
     if ($type === ResponseBag::TYPE_BINARY) {
         $filepath = $responseBag->get(BinaryOutputBuilder::FILEPATH, null);
         $visibility = $responseBag->get(BinaryOutputBuilder::VISIBILITY_PUBLIC, true);
         $autoEtag = $responseBag->get(BinaryOutputBuilder::AUTO_ETAG, false);
         $autoLastModified = $responseBag->get(BinaryOutputBuilder::AUTO_LAST_MODIFIED, true);
         $contentDisposition = $responseBag->get(BinaryOutputBuilder::CONTENT_DISPOSITION, null);
         return new BinaryFileResponse($filepath, $contentDisposition, $visibility, $autoEtag, $autoLastModified);
     }
 }
 public function getHeaders(ResponseBag $bag)
 {
     if (!$bag->has(self::FILENAME)) {
         throw new \Exception('Missing filename for streamed response');
     }
     $bag->addHeader('X-Sendfile', $bag->get(self::FILENAME));
     $bag->addHeader('X-Accel-Buffering', 'no');
     $bag->addHeader('Transfer-Encoding', 'chunked');
     $bag->addHeader('Content-Type', 'application/force-download');
     $bag->addHeader('Content-Disposition', sprintf('%s; filename="%s"', $bag->get(self::ATTACHMENT_DISPOSITION, 'attachment'), $bag->get(self::FILENAME)));
     return $bag->getHeaders();
 }
 public function getHeaders(ResponseBag $bag)
 {
     return $bag->getHeaders();
 }