コード例 #1
0
ファイル: RestClient.php プロジェクト: webpants/YAWIK
 /**
  * Get Request
  *
  * @return Request
  */
 public function getRequest()
 {
     if (empty($this->request)) {
         $headers = new Headers();
         $headers->addHeaders(array('Accept' => 'application/json', 'Content-Type' => 'application/json'));
         $request = parent::getRequest();
         $request->setHeaders($headers);
         $request->setMethod('POST');
     }
     return $this->request;
 }
コード例 #2
0
 /**
  *
  * @return \Zend\View\Model\ViewModel
  */
 public function execute()
 {
     $optionsRenderer = $this->getOptionsRenderer();
     $delimiter = ',';
     if (isset($optionsRenderer['delimiter'])) {
         $delimiter = $optionsRenderer['delimiter'];
     }
     $enclosure = '"';
     if (isset($optionsRenderer['enclosure'])) {
         $enclosure = $optionsRenderer['enclosure'];
     }
     $options = $this->getOptions();
     $optionsExport = $options['settings']['export'];
     $path = $optionsExport['path'];
     $saveFilename = date('Y-m-d_H-i-s') . $this->getCacheId() . '.csv';
     $fp = fopen($path . '/' . $saveFilename, 'w');
     // Force UTF-8 for CSV rendering in EXCEL.
     fprintf($fp, chr(0xef) . chr(0xbb) . chr(0xbf));
     /*
      * Save the file
      */
     // header
     if (isset($optionsRenderer['header']) && true === $optionsRenderer['header']) {
         $header = [];
         foreach ($this->getColumnsToExport() as $col) {
             $header[] = $this->getTranslator()->translate($col->getLabel());
         }
         fputcsv($fp, $header, $delimiter, $enclosure);
     }
     // data
     foreach ($this->getData() as $row) {
         $csvRow = [];
         foreach ($this->getColumnsToExport() as $col) {
             $value = $row[$col->getUniqueId()];
             if ($col->getType() instanceof Type\PhpArray || $col->getType() instanceof Type\Image) {
                 $value = implode(',', $value);
             }
             $csvRow[] = $value;
         }
         fputcsv($fp, $csvRow, $delimiter, $enclosure);
     }
     fclose($fp);
     /*
      * Return the file
      */
     $response = new ResponseStream();
     $response->setStream(fopen($path . '/' . $saveFilename, 'r'));
     $headers = new Headers();
     $headers->addHeaders(['Content-Type' => ['application/force-download', 'application/octet-stream', 'application/download', 'text/csv; charset=utf-8'], 'Content-Length' => filesize($path . '/' . $saveFilename), 'Content-Disposition' => 'attachment;filename=' . $this->getFilename() . '.csv', 'Cache-Control' => 'must-revalidate', 'Pragma' => 'no-cache', 'Expires' => 'Thu, 1 Jan 1970 00:00:00 GMT']);
     $response->setHeaders($headers);
     return $response;
 }
コード例 #3
0
ファイル: File.php プロジェクト: camelcasetechsd/certigate
 /**
  * Get file stream response
  * 
  * 
  * @access public
  * @param string $file
  * @return Stream
  */
 public function getFileResponse($file)
 {
     $response = new Response();
     if (!empty($file) && file_exists($file)) {
         $response = new Stream();
         $response->setStream(fopen($file, 'r'));
         $response->setStatusCode(200);
         $response->setStreamName(basename($file));
         $headers = new Headers();
         $headers->addHeaders(array('Content-Disposition' => 'attachment; filename="' . basename($file) . '"', 'Content-Type' => 'application/octet-stream', 'Content-Length' => filesize($file), 'Expires' => '@0', 'Cache-Control' => 'must-revalidate', 'Pragma' => 'public'));
         $response->setHeaders($headers);
     }
     return $response;
 }
コード例 #4
0
 /**
  * @param  Request  $request
  * @return Response
  */
 public function request(Request $request)
 {
     $headers = new Headers();
     $headers->addHeaders($request->getHeaders());
     $zendRequest = new ZendRequest();
     $zendRequest->setVersion($request->getProtocolVersion());
     $zendRequest->setMethod($request->getMethod());
     $zendRequest->setUri((string) $request->getUrl());
     $zendRequest->setHeaders($headers);
     $zendRequest->setContent($request->getContent());
     /** @var ZendResponse $zendResponse */
     $zendResponse = $this->client->send($zendRequest);
     return new Response((string) $zendResponse->getVersion(), $zendResponse->getStatusCode(), $zendResponse->getReasonPhrase(), $zendResponse->getHeaders()->toArray(), $zendResponse->getContent());
 }
コード例 #5
0
ファイル: Assets.php プロジェクト: zf-hipsters/asset-manager
 public function stream($file, $type)
 {
     switch ($type) {
         case "css":
             $mimeType = 'text/css';
             break;
         case 'js':
             $mimeType = 'text/javascript';
             break;
         default:
             $mimeType = mime_content_type($file);
     }
     $response = new Stream();
     $response->setStream(fopen($file, 'r'));
     $response->setStatusCode(200);
     $response->setStreamName(basename($file));
     $headers = new Headers();
     $headers->addHeaders(array('Content-Type' => $mimeType, 'Content-Length' => filesize($file)));
     $response->setHeaders($headers);
     return $response;
 }
コード例 #6
0
ファイル: ZF2.php プロジェクト: nsgomez/Codeception
 private function extractHeaders(BrowserKitRequest $request)
 {
     $headers = [];
     $server = $request->getServer();
     $contentHeaders = array('Content-Length' => true, 'Content-Md5' => true, 'Content-Type' => true);
     foreach ($server as $header => $val) {
         $header = implode('-', array_map('ucfirst', explode('-', strtolower(str_replace('_', '-', $header)))));
         if (strpos($header, 'Http-') === 0) {
             $headers[substr($header, 5)] = $val;
         } elseif (isset($contentHeaders[$header])) {
             $headers[$header] = $val;
         }
     }
     $zendHeaders = new HttpHeaders();
     $zendHeaders->addHeaders($headers);
     return $zendHeaders;
 }
コード例 #7
0
ファイル: Controller.php プロジェクト: Belcebur/BelceburBasic
 public function downloadFile($filePath, $filename = FALSE)
 {
     $name = $filename ?: basename($filePath);
     $response = new Stream();
     $response->setStream(fopen($filePath, 'r'));
     $response->setStatusCode(200);
     $response->setStreamName(basename($filePath));
     $headers = new Headers();
     $headers->addHeaders(array('Content-Disposition' => "attachment; filename='{$name}'", 'Content-Type' => 'application/octet-stream', 'Content-Length' => filesize($filePath), 'Expires' => '@0', 'Cache-Control' => 'must-revalidate', 'Pragma' => 'public'));
     $response->setHeaders($headers);
     return $response;
 }
コード例 #8
0
 /**
  * Execute the request
  *
  * @param RequestInterface $request
  * @param ResponseInterface $response (Default: null)
  * @return \Zend\Http\PhpEnvironment\Response
  */
 public function dispatch(RequestInterface $request, ResponseInterface $response = null)
 {
     // the config hash
     $config = $this->getServiceLocator()->get('Config');
     $config = $config['TpMinify'];
     // some important stuff
     $config['serveOptions']['quiet'] = true;
     // the time correction
     Minify::$uploaderHoursBehind = $config['uploaderHoursBehind'];
     // the cache engine
     Minify::setCache($config['cachePath'] ?: '', $config['cacheFileLocking']);
     // doc root corrections
     if ($config['documentRoot']) {
         $_SERVER['DOCUMENT_ROOT'] = $config['documentRoot'];
         Minify::$isDocRootSet = true;
     }
     // check for URI versioning
     if (preg_match('~&\\d~', $request->getUriString())) {
         $config['serveOptions']['maxAge'] = 31536000;
     }
     // minify result as array of information
     $result = Minify::serve('MinApp', $config['serveOptions']);
     // some corrections
     if (isset($result['headers']['_responseCode'])) {
         unset($result['headers']['_responseCode']);
     }
     // the headers set
     $headers = new Headers();
     $headers->addHeaders($result['headers']);
     // final output
     return $response->setHeaders($headers)->setStatusCode($result['statusCode'])->setContent($result['content']);
 }
コード例 #9
0
 protected function saveAndSend()
 {
     $pdf = $this->getPdf();
     $options = $this->getOptions();
     $optionsExport = $options['settings']['export'];
     $path = $optionsExport['path'];
     $saveFilename = $this->getCacheId() . '.pdf';
     $pdf->Output($path . '/' . $saveFilename, 'F');
     $response = new ResponseStream();
     $response->setStream(fopen($path . '/' . $saveFilename, 'r'));
     $headers = new Headers();
     $headers->addHeaders(array('Content-Type' => array('application/force-download', 'application/octet-stream', 'application/download'), 'Content-Length' => filesize($path . '/' . $saveFilename), 'Content-Disposition' => 'attachment;filename=' . $this->getFilename() . '.pdf', 'Cache-Control' => 'must-revalidate', 'Pragma' => 'no-cache', 'Expires' => 'Thu, 1 Jan 1970 00:00:00 GMT'));
     $response->setHeaders($headers);
     return $response;
 }
コード例 #10
0
ファイル: HeadersTest.php プロジェクト: JojoBombardo/zf2
 public function testHeadersCanBeCastToArray()
 {
     $headers = new Headers();
     $headers->addHeaders(array('Foo' => 'bar', 'Baz' => 'baz'));
     $this->assertEquals(array('Foo' => 'bar', 'Baz' => 'baz'), $headers->toArray());
 }
コード例 #11
0
 public function pdfAction()
 {
     $number = (int) $this->params()->fromRoute('id', 0);
     $file = 'data/invoice/invoice-' . sprintf('%06d', $number) . '.pdf';
     $response = new Stream();
     $response->setStream(fopen($file, 'r'));
     $response->setStreamName(basename($file));
     $headers = new Headers();
     $headers->addHeaders(array('Content-Disposition' => 'attachment; filename="' . basename($file) . '"', 'Content-Type' => 'application/pdf', 'Content-Length' => filesize($file)));
     $response->setHeaders($headers);
     return $response;
 }
コード例 #12
0
 public function viewFileAttachmentAction()
 {
     $file_no = (int) $this->params()->fromRoute('id', 0);
     if (!$file_no) {
         return $this->redirect()->toRoute('app', array('controller' => 'failed', 'action' => 'forbidden'));
     }
     $currentUser = $this->auth()->get('user_no');
     $dbAdapter = $this->getDb();
     $sql = "SELECT \n                      t_decision_file.file_no, \n                      t_decision_file.decision_no, \n                      t_decision_file.file_name, \n                      t_decision_file.content_type, \n                      OCTET_LENGTH( t_decision_file.binary_data) as file_size, \n                      t_decision_file.binary_data,\n                      t_decision.create_user\n                 FROM t_decision_file \n            LEFT JOIN t_decision \n                   ON t_decision_file.decision_no = t_decision.decision_no\n                WHERE t_decision_file.file_no = {$file_no}";
     $result = $dbAdapter->query($sql)->execute();
     $file = $result->current();
     if (!$file) {
         return $this->redirect()->toRoute('app', array('controller' => 'failed', 'action' => 'not-found'));
     }
     $continue = true;
     // you must be the create user of the request
     if ($file['create_user'] != $currentUser) {
         $continue = false;
     }
     // if you are not the create_user of the request you must be 1 of approver
     if (!$continue) {
         // check file restriction
         $result2 = $dbAdapter->query("SELECT\n                    t_decision_approval.user_no\n                    FROM t_decision_approval\n                    WHERE t_decision_approval.decision_no = {$file['decision_no']}")->execute();
         $resultSet = new ResultSet();
         $resultSet->initialize($result2);
         $resultAr = $resultSet->toArray();
         if (is_array($resultAr)) {
             foreach ($resultAr as $rec) {
                 if ((int) $rec['user_no'] === (int) $currentUser) {
                     $continue = true;
                     break;
                 }
             }
         }
     }
     // Otherwise you will not be able to access this attachment
     if (!$continue) {
         $this->flashMessenger()->addMessage("You don't have enough access level to view this document");
         return $this->redirect()->toRoute('app', array('controller' => 'failed', 'action' => 'forbidden'));
     }
     $file_name = $file["file_name"];
     $file_size = $file["file_size"];
     $file_mime_type = $file["content_type"];
     $file_content = $file["binary_data"];
     $new_filename = "temp_" . $file_name;
     $filePath = APP_UPLOAD_DIR . $new_filename;
     \file_put_contents($filePath, $file_content);
     $response = new Stream();
     $response->setStream(fopen($filePath, 'r'));
     $response->setStatusCode(200);
     $response->setStreamName(basename($filePath));
     $headers = new Headers();
     $headers->addHeaders(array('Content-Disposition' => 'inline; filename="' . $new_filename . '"', 'Content-Type' => $file_mime_type . ';charset=UTF-8', 'Content-Length' => $file_size));
     $response->setHeaders($headers);
     /**$view = new ViewModel(array(
            'response' => $response,
            'headers' => $headers
        ));
        $view->setTemplate('/common/view-attachment.phtml');
        $view->setTerminal(true);**/
     //  return $view;
     return $response;
 }
コード例 #13
0
 /**
  * @param $file
  * @return Stream
  */
 function forceDownloadAction($file)
 {
     //        $file = '/path/to/my/file.txt';
     $file = $_SERVER['DOCUMENT_ROOT'] . '/' . $file;
     $response = new Stream();
     $response->setStream(fopen($file, 'r'));
     $response->setStatusCode(200);
     $response->setStreamName(basename($file));
     $headers = new Headers();
     $headers->addHeaders(array('Content-Disposition' => 'attachment; filename="' . basename($file) . '"', 'Content-Type' => 'application/octet-stream', 'Content-Length' => filesize($file)));
     $response->setHeaders($headers);
     return $response;
 }
コード例 #14
0
 public function execute()
 {
     if ($this->getFindException()) {
         foreach ($this->getReasonsException() as $key => $reason) {
             $msg[$key] = $reason;
         }
         if ($reason !== null) {
             return $this->raiseError($reason, $key);
         }
     }
     $options = $this->getOptions();
     $optionsExport = $options['settings']['export'];
     $optionsRenderer = $this->getOptionsRenderer();
     $phpExcel = new PHPExcel();
     // Sheet 1
     $phpExcel->setActiveSheetIndex(0);
     $sheet = $phpExcel->getActiveSheet();
     $sheet->setTitle($this->getTranslator()->translate($optionsRenderer['sheetName']));
     if ($optionsRenderer['displayTitle'] === true) {
         $sheet->setCellValue('A' . $optionsRenderer['rowTitle'], $this->getTitle());
         $sheet->getStyle('A' . $optionsRenderer['rowTitle'])->getFont()->setSize(15);
     }
     $this->calculateColumnWidth($this->getColumnsToExport());
     $xColumn = 0;
     $yRow = $optionsRenderer['startRowData'];
     foreach ($this->getColumnsToExport() as $column) {
         /* @var $column \Zf2datatable\Column\AbstractColumn */
         //$label = $this->getTranslator()->translate($column->getLabel());
         $label = $column->getLabel();
         $sheet->setCellValueByColumnAndRow($xColumn, $yRow, $label);
         // $sheet->getColumnDimension(PHPExcel_Cell::stringFromColumnIndex($xColumn))->setCollapsed(true);
         $sheet->getColumnDimension(PHPExcel_Cell::stringFromColumnIndex($xColumn))->setWidth($column->getWidth());
         $xColumn++;
     }
     /*
      * Data
      */
     $yRow = $optionsRenderer['startRowData'] + 1;
     foreach ($this->getData() as $row) {
         $xColumn = 0;
         foreach ($this->getColumnsToExport() as $column) {
             /* @var $column \Zf2datatable\Column\AbstractColumn */
             $currentColumn = PHPExcel_Cell::stringFromColumnIndex($xColumn);
             $sheet->getCell($currentColumn . $yRow)->setValueExplicit($row[$column->getUniqueId()], PHPExcel_Cell_DataType::TYPE_STRING);
             $columnStyle = $sheet->getStyle($currentColumn . $yRow);
             $columnStyle->getAlignment()->setWrapText(true);
             /*
              * Styles
              */
             $styles = array_merge($this->getRowStyles(), $column->getStyles());
             foreach ($styles as $style) {
                 /* @var $style \Zf2datatable\Column\Style\AbstractStyle */
                 if ($style->isApply($row) === true) {
                     switch (get_class($style)) {
                         case 'Zf2datatable\\Column\\Style\\Bold':
                             $columnStyle->getFont()->setBold(true);
                             break;
                         case 'Zf2datatable\\Column\\Style\\Italic':
                             $columnStyle->getFont()->setItalic(true);
                             break;
                         case 'Zf2datatable\\Column\\Style\\Color':
                             $columnStyle->getFont()->getColor()->setRGB($style->getRgbHexString());
                             break;
                         case 'Zf2datatable\\Column\\Style\\BackgroundColor':
                             $columnStyle->getFill()->applyFromArray(array('type' => \PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('rgb' => $style->getRgbHexString())));
                             break;
                         default:
                             throw new \Exception('Not defined yet: "' . get_class($style) . '"');
                             break;
                     }
                 }
             }
             $xColumn++;
         }
         $yRow++;
     }
     /*
      * Autofilter, freezing, ...
      */
     // Letzte Zeile merken
     $endRow = $yRow - 1;
     $endColumn = count($this->getColumnsToExport()) - 1;
     // Autofilter + Freeze
     $sheet->setAutoFilter('A' . $optionsRenderer['startRowData'] . ':' . PHPExcel_Cell::stringFromColumnIndex($endColumn) . $endRow);
     $freezeRow = $optionsRenderer['startRowData'] + 1;
     $sheet->freezePane('A' . $freezeRow);
     /*
      * Print settings
      */
     $this->setPrinting($phpExcel);
     /*
      * Save the file
      */
     $path = $optionsExport['path'];
     $saveFilename = $this->getCacheId() . '.xlsx';
     $excelWriter = new \PHPExcel_Writer_Excel2007($phpExcel);
     $excelWriter->setPreCalculateFormulas(false);
     $excelWriter->save($path . '/' . $saveFilename);
     /*
      * Send the response stream
      */
     $response = new ResponseStream();
     $response->setStream(fopen($path . '/' . $saveFilename, 'r'));
     $headers = new Headers();
     $headers->addHeaders(array('Content-Type' => array('application/force-download', 'application/octet-stream', 'application/download'), 'Content-Length' => filesize($path . '/' . $saveFilename), 'Content-Disposition' => 'attachment;filename=' . $this->getFilename() . '.xlsx', 'Cache-Control' => 'must-revalidate', 'Pragma' => 'no-cache', 'Expires' => 'Thu, 1 Jan 1970 00:00:00 GMT'));
     $response->setHeaders($headers);
     return $response;
 }
コード例 #15
0
 public function execute()
 {
     $options = $this->getOptions();
     $optionsExport = $options['settings']['export'];
     $optionsRenderer = $this->getOptionsRenderer();
     $phpExcel = new PHPExcel();
     // Sheet 1
     $phpExcel->setActiveSheetIndex(0);
     $sheet = $phpExcel->getActiveSheet();
     $sheet->setTitle($this->getTranslator()->translate($optionsRenderer['sheetName']));
     if (true === $optionsRenderer['displayTitle']) {
         $sheet->setCellValue('A' . $optionsRenderer['rowTitle'], $this->getTitle());
         $sheet->getStyle('A' . $optionsRenderer['rowTitle'])->getFont()->setSize(15);
     }
     /*
      * Print settings
      */
     $this->setPrinting($phpExcel);
     /*
      * Calculate column width
      */
     $this->calculateColumnWidth($sheet, $this->getColumnsToExport());
     /*
      * Header
      */
     $xColumn = 0;
     $yRow = $optionsRenderer['startRowData'];
     foreach ($this->getColumnsToExport() as $col) {
         /* @var $column \ZfcDatagrid\Column\AbstractColumn */
         $label = $this->getTranslator()->translate($col->getLabel());
         $sheet->setCellValueByColumnAndRow($xColumn, $yRow, $label);
         $sheet->getColumnDimension(PHPExcel_Cell::stringFromColumnIndex($xColumn))->setWidth($col->getWidth());
         $xColumn++;
     }
     /*
      * Data
      */
     $yRow = $optionsRenderer['startRowData'] + 1;
     foreach ($this->getData() as $row) {
         $xColumn = 0;
         foreach ($this->getColumnsToExport() as $col) {
             $value = $row[$col->getUniqueId()];
             if (is_array($value)) {
                 $value = implode(PHP_EOL, $value);
             }
             /* @var $column \ZfcDatagrid\Column\AbstractColumn */
             $currentColumn = PHPExcel_Cell::stringFromColumnIndex($xColumn);
             $sheet->getCell($currentColumn . $yRow)->setValueExplicit($value, PHPExcel_Cell_DataType::TYPE_STRING);
             $columnStyle = $sheet->getStyle($currentColumn . $yRow);
             $columnStyle->getAlignment()->setWrapText(true);
             /*
              * Styles
              */
             $styles = array_merge($this->getRowStyles(), $col->getStyles());
             foreach ($styles as $style) {
                 /* @var $style \ZfcDatagrid\Column\Style\AbstractStyle */
                 if ($style->isApply($row) === true) {
                     switch (get_class($style)) {
                         case 'ZfcDatagrid\\Column\\Style\\Bold':
                             $columnStyle->getFont()->setBold(true);
                             break;
                         case 'ZfcDatagrid\\Column\\Style\\Italic':
                             $columnStyle->getFont()->setItalic(true);
                             break;
                         case 'ZfcDatagrid\\Column\\Style\\Color':
                             $columnStyle->getFont()->getColor()->setRGB($style->getRgbHexString());
                             break;
                         case 'ZfcDatagrid\\Column\\Style\\BackgroundColor':
                             $columnStyle->getFill()->applyFromArray(['type' => \PHPExcel_Style_Fill::FILL_SOLID, 'color' => ['rgb' => $style->getRgbHexString()]]);
                             break;
                         case 'ZfcDatagrid\\Column\\Style\\Align':
                             switch ($style->getAlignment()) {
                                 case \ZfcDatagrid\Column\Style\Align::$RIGHT:
                                     $columnStyle->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
                                     break;
                                 case \ZfcDatagrid\Column\Style\Align::$LEFT:
                                     $columnStyle->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
                                     break;
                                 case \ZfcDatagrid\Column\Style\Align::$CENTER:
                                     $columnStyle->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
                                     break;
                                 case \ZfcDatagrid\Column\Style\Align::$JUSTIFY:
                                     $columnStyle->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY);
                                     break;
                                 default:
                                     //throw new \Exception('Not defined yet: "'.get_class($style->getAlignment()).'"');
                                     break;
                             }
                             break;
                         case 'ZfcDatagrid\\Column\\Style\\Strikethrough':
                             $columnStyle->getFont()->setStrikethrough(true);
                             break;
                         case 'ZfcDatagrid\\Column\\Style\\Html':
                             // @todo strip the html?
                             break;
                         default:
                             throw new \Exception('Not defined yet: "' . get_class($style) . '"');
                             break;
                     }
                 }
             }
             $xColumn++;
         }
         $yRow++;
     }
     /*
      * Autofilter, freezing, ...
      */
     $highest = $sheet->getHighestRowAndColumn();
     // Letzte Zeile merken
     // Autofilter + Freeze
     $sheet->setAutoFilter('A' . $optionsRenderer['startRowData'] . ':' . $highest['column'] . $highest['row']);
     $freezeRow = $optionsRenderer['startRowData'] + 1;
     $sheet->freezePane('A' . $freezeRow);
     // repeat the data header for each page!
     $sheet->getPageSetup()->setRowsToRepeatAtTopByStartAndEnd($optionsRenderer['startRowData'], $optionsRenderer['startRowData']);
     // highlight header line
     $style = ['font' => ['bold' => true], 'borders' => ['allborders' => ['style' => PHPExcel_Style_Border::BORDER_MEDIUM, 'color' => ['argb' => PHPExcel_Style_Color::COLOR_BLACK]]], 'fill' => ['type' => PHPExcel_Style_Fill::FILL_SOLID, 'startcolor' => ['argb' => PHPExcel_Style_Color::COLOR_YELLOW]]];
     $range = 'A' . $optionsRenderer['startRowData'] . ':' . $highest['column'] . $optionsRenderer['startRowData'];
     $sheet->getStyle($range)->applyFromArray($style);
     // print borders
     $range = 'A' . $freezeRow . ':' . $highest['column'] . $highest['row'];
     $sheet->getStyle($range)->applyFromArray(['borders' => ['allborders' => ['style' => PHPExcel_Style_Border::BORDER_THIN]]]);
     /*
      * Save the file
      */
     $path = $optionsExport['path'];
     $saveFilename = date('Y-m-d_H-i-s') . $this->getCacheId() . '.xlsx';
     $excelWriter = new \PHPExcel_Writer_Excel2007($phpExcel);
     $excelWriter->setPreCalculateFormulas(false);
     $excelWriter->save($path . '/' . $saveFilename);
     /*
      * Send the response stream
      */
     $response = new ResponseStream();
     $response->setStream(fopen($path . '/' . $saveFilename, 'r'));
     $headers = new Headers();
     $headers->addHeaders(['Content-Type' => ['application/force-download', 'application/octet-stream', 'application/download'], 'Content-Length' => filesize($path . '/' . $saveFilename), 'Content-Disposition' => 'attachment;filename=' . $this->getFilename() . '.xlsx', 'Cache-Control' => 'must-revalidate', 'Pragma' => 'no-cache', 'Expires' => 'Thu, 1 Jan 1970 00:00:00 GMT']);
     $response->setHeaders($headers);
     return $response;
 }
コード例 #16
0
ファイル: Client.php プロジェクト: tillk/vufind
 /**
  * Set the headers (for the request)
  *
  * @param  Headers|array $headers
  * @throws Exception\InvalidArgumentException
  * @return Client
  */
 public function setHeaders($headers)
 {
     if (is_array($headers)) {
         $newHeaders = new Headers();
         $newHeaders->addHeaders($headers);
         $this->getRequest()->setHeaders($newHeaders);
     } elseif ($headers instanceof Headers) {
         $this->getRequest()->setHeaders($headers);
     } else {
         throw new Exception\InvalidArgumentException('Invalid parameter headers passed');
     }
     return $this;
 }
コード例 #17
0
ファイル: ZF2.php プロジェクト: namnv609/Codeception
 private function extractHeaders(BrowserKitRequest $request)
 {
     $headers = [];
     $server = $request->getServer();
     $uri = new Uri($request->getUri());
     $server['HTTP_HOST'] = $uri->getHost();
     $port = $uri->getPort();
     if ($port !== null && $port !== 443 && $port != 80) {
         $server['HTTP_HOST'] .= ':' . $port;
     }
     $contentHeaders = array('Content-Length' => true, 'Content-Md5' => true, 'Content-Type' => true);
     foreach ($server as $header => $val) {
         $header = implode('-', array_map('ucfirst', explode('-', strtolower(str_replace('_', '-', $header)))));
         if (strpos($header, 'Http-') === 0) {
             $headers[substr($header, 5)] = $val;
         } elseif (isset($contentHeaders[$header])) {
             $headers[$header] = $val;
         }
     }
     $zendHeaders = new HttpHeaders();
     $zendHeaders->addHeaders($headers);
     return $zendHeaders;
 }
コード例 #18
-1
 /**
  * @param MvcEvent $event
  */
 public function onDispatchError(MvcEvent $event)
 {
     if (Application::ERROR_ROUTER_NO_MATCH != $event->getError()) {
         // ignore other than 'no route' errors
         return;
     }
     // get URI stripped of a base URL
     $request = $event->getRequest();
     $uri = str_replace($request->getBaseUrl(), '', $request->getRequestUri());
     // try get image ID from URI
     $id = $this->manager->matchUri($uri);
     if (!$id) {
         // abort if URI does not match
         return;
     }
     // try get image from repository
     $image = $this->repository->find($id);
     if (!$image) {
         // abort if image does not exist
         return;
     }
     // store image
     $this->manager->store($image);
     // return image in response as a stream
     $headers = new Headers();
     $headers->addHeaders(['Content-Type' => $image->getType(), 'Content-Length' => $image->getLength()]);
     $response = new Stream();
     $response->setStatusCode(Response::STATUS_CODE_200);
     $response->setStream($image->getResource());
     $response->setStreamName($image->getName());
     $response->setHeaders($headers);
     $event->setResponse($response);
 }