Пример #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);
     }
 }