当前位置: 首页>>代码示例>>PHP>>正文


PHP ResponseInterface::setHttpResponseCode方法代码示例

本文整理汇总了PHP中Magento\Framework\App\ResponseInterface::setHttpResponseCode方法的典型用法代码示例。如果您正苦于以下问题:PHP ResponseInterface::setHttpResponseCode方法的具体用法?PHP ResponseInterface::setHttpResponseCode怎么用?PHP ResponseInterface::setHttpResponseCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Framework\App\ResponseInterface的用法示例。


在下文中一共展示了ResponseInterface::setHttpResponseCode方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: _sendUploadResponse

 protected function _sendUploadResponse($fileName, $content, $contentType = 'application/octet-stream')
 {
     $this->_response->setHttpResponseCode(200)->setHeader('Pragma', 'public', true)->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true)->setHeader('Content-type', $contentType, true)->setHeader('Content-Length', strlen($content))->setHeader('Content-Disposition', 'attachment; filename="' . $fileName . '"', true)->setHeader('Last-Modified', date('r'), true);
     $this->_response->setBody($content);
     $this->_response->sendResponse();
     die;
     return $this->_response;
 }
开发者ID:rustamveer,项目名称:magento2,代码行数:8,代码来源:Save.php

示例2: create

 /**
  * Declare headers and content file in response for file download
  *
  * @param string $fileName
  * @param string|array $content set to null to avoid starting output, $contentLength should be set explicitly in
  *                              that case
  * @param string $baseDir
  * @param string $contentType
  * @param int $contentLength explicit content length, if strlen($content) isn't applicable
  * @throws \Exception
  * @throws \InvalidArgumentException
  * @return \Magento\Framework\App\ResponseInterface
  *
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.ExitExpression)
  */
 public function create($fileName, $content, $baseDir = DirectoryList::ROOT, $contentType = 'application/octet-stream', $contentLength = null)
 {
     $dir = $this->_filesystem->getDirectoryWrite($baseDir);
     $isFile = false;
     $file = null;
     if (is_array($content)) {
         if (!isset($content['type']) || !isset($content['value'])) {
             throw new \InvalidArgumentException("Invalid arguments. Keys 'type' and 'value' are required.");
         }
         if ($content['type'] == 'filename') {
             $isFile = true;
             $file = $content['value'];
             if (!$dir->isFile($file)) {
                 throw new \Exception((string) new \Magento\Framework\Phrase('File not found'));
             }
             $contentLength = $dir->stat($file)['size'];
         }
     }
     $this->_response->setHttpResponseCode(200)->setHeader('Pragma', 'public', true)->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true)->setHeader('Content-type', $contentType, true)->setHeader('Content-Length', $contentLength === null ? strlen($content) : $contentLength, true)->setHeader('Content-Disposition', 'attachment; filename="' . $fileName . '"', true)->setHeader('Last-Modified', date('r'), true);
     if ($content !== null) {
         $this->_response->sendHeaders();
         if ($isFile) {
             $stream = $dir->openFile($file, 'r');
             while (!$stream->eof()) {
                 echo $stream->read(1024);
             }
         } else {
             $dir->writeFile($fileName, $content);
             $stream = $dir->openFile($fileName, 'r');
             while (!$stream->eof()) {
                 echo $stream->read(1024);
             }
         }
         $stream->close();
         flush();
         if (!empty($content['rm'])) {
             $dir->delete($file);
         }
         $this->callExit();
     }
     return $this->_response;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:59,代码来源:FileFactory.php

示例3: downloadFileOption

 /**
  * Fetches and outputs file to user browser
  * $info is array with following indexes:
  *  - 'path' - full file path
  *  - 'type' - mime type of file
  *  - 'size' - size of file
  *  - 'title' - user-friendly name of file (usually - original name as uploaded in Magento)
  *
  * @param \Magento\Framework\App\ResponseInterface $response
  * @param string $filePath
  * @param array $info
  * @return bool
  */
 public function downloadFileOption($response, $filePath, $info)
 {
     try {
         $response->setHttpResponseCode(200)->setHeader('Pragma', 'public', true)->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true)->setHeader('Content-type', $info['type'], true)->setHeader('Content-Length', $info['size'])->setHeader('Content-Disposition', 'inline' . '; filename=' . $info['title'])->clearBody();
         $response->sendHeaders();
         echo $this->directory->readFile($this->directory->getRelativePath($filePath));
     } catch (\Exception $e) {
         return false;
     }
     return true;
 }
开发者ID:aiesh,项目名称:magento2,代码行数:24,代码来源:Options.php

示例4: applyHttpHeaders

 /**
  * @param ResponseInterface $response
  * @return $this
  */
 protected function applyHttpHeaders(ResponseInterface $response)
 {
     if (!empty($this->httpResponseCode)) {
         $response->setHttpResponseCode($this->httpResponseCode);
     }
     if ($this->statusHeaderCode) {
         $response->setStatusHeader($this->statusHeaderCode, $this->statusHeaderVersion, $this->statusHeaderPhrase);
     }
     if (!empty($this->headers)) {
         foreach ($this->headers as $headerData) {
             $response->setHeader($headerData['name'], $headerData['value'], $headerData['replace']);
         }
     }
     return $this;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:19,代码来源:AbstractResult.php


注:本文中的Magento\Framework\App\ResponseInterface::setHttpResponseCode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。