本文整理汇总了PHP中Zend\Http\Headers::addHeaders方法的典型用法代码示例。如果您正苦于以下问题:PHP Headers::addHeaders方法的具体用法?PHP Headers::addHeaders怎么用?PHP Headers::addHeaders使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Http\Headers
的用法示例。
在下文中一共展示了Headers::addHeaders方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getRequest
/**
* 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: execute
/**
*
* @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: getFileResponse
/**
* 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: request
/**
* @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: stream
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: extractHeaders
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: downloadFile
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: dispatch
/**
* 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: saveAndSend
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: testHeadersCanBeCastToArray
public function testHeadersCanBeCastToArray()
{
$headers = new Headers();
$headers->addHeaders(array('Foo' => 'bar', 'Baz' => 'baz'));
$this->assertEquals(array('Foo' => 'bar', 'Baz' => 'baz'), $headers->toArray());
}
示例11: pdfAction
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: viewFileAttachmentAction
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: forceDownloadAction
/**
* @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: 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 ($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: setHeaders
/**
* 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;
}