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


PHP Response::getHeaders方法代码示例

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


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

示例1: testRebuild

 public function testRebuild()
 {
     $expectedContent = ['foo' => 'bar'];
     $expectedHeaders = new \Phalcon\Http\Response\Headers();
     $expectedHeaders->set('Status', '200 OK');
     $expectedHeaders->set('HTTP/1.1 200 OK', null);
     $this->response->rebuild(['foo' => 'bar']);
     $this->assertEquals($expectedContent, $this->response->getContent());
     $this->assertEquals($expectedHeaders, $this->response->getHeaders());
 }
开发者ID:ovide,项目名称:phest,代码行数:10,代码来源:ResponseTest.php

示例2: handle

 /**
  * @param Response $response
  */
 public function handle(Response $response)
 {
     foreach ($response->getHeaders() as $header) {
         header($header);
     }
     echo $response->getContent();
 }
开发者ID:edefine,项目名称:framework,代码行数:10,代码来源:ResponseHandler.php

示例3: format

 /**
  * 格式化指定的响应
  *
  * @param Response $response
  */
 public function format($response)
 {
     if (stripos($this->contentType, 'charset') === false) {
         $this->contentType .= '; charset=' . $response->charset;
     }
     $response->getHeaders()->set('Content-Type', $this->contentType);
     $response->content = $response->data;
 }
开发者ID:smallmirror62,项目名称:framework,代码行数:13,代码来源:HtmlFormatter.php

示例4: buildMessage

 public function buildMessage(Response $response)
 {
     $str = '';
     $str .= $response->getStatus();
     $str .= "\nURL:\n" . $response->getUrl();
     $str .= "\nPARAMS:\n" . var_export($response->getParams(), true);
     $str .= "\nRESPONSE HEADER:\n" . var_export($response->getHeaders(), true);
     $str .= "\nRESPONSE CONTENT:\n" . substr($response->getContent(), 0, 200);
     return $str;
 }
开发者ID:nikonehauser,项目名称:ptclient,代码行数:10,代码来源:ResponseException.php

示例5: construct

 /**
  * Verify basic functionality of the response object.
  *
  * @test
  * @covers ::__construct
  * @covers ::getHttpCode
  * @covers ::getHeaders
  * @covers ::getBody
  *
  * @return void
  */
 public function construct()
 {
     $httpCode = 200;
     $headers = ['Content-Type' => 'text/json'];
     $body = ['doesnt' => 'matter'];
     $response = new Response($httpCode, $headers, $body);
     $this->assertSame($httpCode, $response->getHttpCode());
     $this->assertSame($headers, $response->getHeaders());
     $this->assertSame($body, $response->getBody());
 }
开发者ID:chadicus,项目名称:marvel-api-client,代码行数:21,代码来源:ResponseTest.php

示例6: render

 /**
  * {@inheritdoc}
  */
 public function render(Request $request, Response $response)
 {
     if (!$this->environment->isSilent()) {
         header('HTTP/1.1 ' . $response->getStatusCode() . ' ' . $response->getStatusMessage());
         foreach ($response->getHeaders() as $name => $value) {
             header($name . ': ' . $value);
         }
     }
     echo $this->createTemplate($response);
 }
开发者ID:itephp,项目名称:framework,代码行数:13,代码来源:HTTPErrorPresenter.php

示例7: render

 /** Renders a response. */
 public final function render(Response $response)
 {
     foreach ($response->getHeaders() as $h) {
         header($h);
     }
     http_response_code($response->getStatus());
     $e = $response->getEntity();
     if (!is_null($e)) {
         $this->renderEntity($e);
     }
 }
开发者ID:andresrc,项目名称:tcus-php-as,代码行数:12,代码来源:View.php

示例8: sendHeaders

 /**
  * Sends the headers of the response to the client.
  *
  * @return void
  */
 protected function sendHeaders()
 {
     if (!headers_sent()) {
         $status = $this->response->getMessage() ?: $this->response->getStatus();
         header(sprintf("%s %s", $this->response->getProtocol(), $status));
         foreach ($this->response->getHeaders() as $name => $value) {
             header("{$name}: {$value}", true);
         }
         foreach ($this->response->getCookies() as $cookie) {
             header("Set-Cookie: {$cookie}", false);
         }
     }
 }
开发者ID:rawebone,项目名称:wilson,代码行数:18,代码来源:Sender.php

示例9: format

 /**
  * Formats the specified response.
  * @param Response $response the response to be formatted.
  */
 public function format($response)
 {
     $charset = $this->encoding === null ? $response->charset : $this->encoding;
     if (stripos($this->contentType, 'charset') === false) {
         $this->contentType .= '; charset=' . $charset;
     }
     $response->getHeaders()->set('Content-Type', $this->contentType);
     $dom = new DOMDocument($this->version, $charset);
     $root = $dom->createElement($this->rootTag);
     $root->setAttribute('xmlns', $this->xmlns);
     $dom->appendChild($root);
     $this->buildXml($root, $response->data);
     $response->content = $dom->saveXML();
 }
开发者ID:advance100,项目名称:yunjianyi,代码行数:18,代码来源:IndexResponseFormatter.php

示例10: format

 /**
  * Formats the specified response.
  * @param Response $response the response to be formatted.
  */
 public function format($response)
 {
     $charset = $this->encoding === null ? $response->charset : $this->encoding;
     if ($this->gzip) {
         $this->contentType = $this->gzipContentType;
     } elseif (stripos($this->contentType, 'charset') === false) {
         $this->contentType .= '; charset=' . $charset;
     }
     $response->getHeaders()->set('Content-Type', $this->contentType);
     $dom = new DOMDocument($this->version, $charset);
     $root = $dom->createElement($this->rootTag);
     $root->setAttribute('xmlns', $this->xmlns);
     $dom->appendChild($root);
     $this->buildXml($root, $response->data);
     $xmlData = $dom->saveXML();
     //output
     if ($this->gzip) {
         $response->content = gzencode($xmlData);
         $response->getHeaders()->set('Content-Disposition', "attachment; filename=\"{$this->gzipFilename}\"");
     } else {
         $response->content = $xmlData;
     }
 }
开发者ID:advance100,项目名称:yunjianyi,代码行数:27,代码来源:UrlsetResponseFormatter.php

示例11: __construct

 public function __construct(Response $parent)
 {
     $status = $parent->getStatus();
     $convertToJson = false;
     $ok = self::statusIsOK($status);
     if ($ok) {
         $contentType = $parent->getHeader('Content-Type');
         if (!empty($contentType)) {
             $convertToJson = stristr($contentType, '/json') !== false;
         }
     }
     $bodyString = $parent->getBody();
     parent::__construct($convertToJson ? json_decode($bodyString) : $bodyString, $parent->getHeaders(), $status);
     $this->ok = $ok;
 }
开发者ID:jonasvr,项目名称:lockedornot,代码行数:15,代码来源:InfogramResponse.php

示例12: format

 /**
  * Formats the specified response.
  * @param Response $response the response to be formatted.
  * @throws \RuntimeException
  */
 public function format($response)
 {
     $response->getHeaders()->set('Content-Type', 'text/csv; charset=UTF-8');
     $handle = fopen('php://temp/maxmemory:' . intval($this->maxMemory), 'w+');
     $response->stream = $handle;
     if ($this->includeColumnNames && $this->checkAllRows) {
         $columns = $this->getColumnNames($response->data);
         if (empty($columns)) {
             return;
         }
         $outputHeader = false;
         $this->put($handle, $columns);
     } else {
         $outputHeader = true;
     }
     if (!$response->data instanceof \Traversable && !is_array($response->data)) {
         throw new \InvalidArgumentException('Response data must be traversable.');
     }
     foreach ($response->data as $row) {
         if ($outputHeader && $this->includeColumnNames && !$this->checkAllRows && \yii\helpers\ArrayHelper::isAssociative($row)) {
             $this->put($handle, array_keys($row));
             $outputHeader = false;
         }
         if ($row instanceof Arrayable) {
             $row = $row->toArray();
         }
         $rowData = [];
         if (isset($columns)) {
             // Map columns.
             foreach ($columns as $column) {
                 if (array_key_exists($column, $row)) {
                     $rowData[] = isset($row[$column]) ? $row[$column] : $this->nullValue;
                 } else {
                     $rowData[] = $this->missingValue;
                 }
             }
         } else {
             foreach ($row as $column => $value) {
                 $rowData[] = isset($value) ? $value : $this->nullValue;
             }
         }
         $this->put($handle, $rowData);
     }
     rewind($handle);
 }
开发者ID:sam-it,项目名称:yii2-csv-formatter,代码行数:50,代码来源:CsvResponseFormatter.php

示例13: format

 /**
  * Formats the specified response.
  * @param Response $response the response to be formatted.
  */
 public function format($response)
 {
     $charset = $this->encoding === null ? $response->charset : $this->encoding;
     if (stripos($this->contentType, 'charset') === false) {
         $this->contentType .= '; charset=' . $charset;
     }
     $response->getHeaders()->set('Content-Type', $this->contentType);
     if ($response->data !== null) {
         $dom = new DOMDocument($this->version, $charset);
         $root = new DOMElement($this->rootTag);
         $result = new DOMElement($this->itemTag);
         $code = new DOMElement($this->itemTag);
         $status = new DOMElement($this->itemTag);
         $dom->appendChild($root);
         $code->appendChild($response->getStatusCode());
         $status->appendChild($response->getIsSuccessful() ? 'success' : 'error');
         $messageText = '';
         if (!$response->getIsOk()) {
             $messageText = $response->statusText;
         }
         if (is_string($response->data)) {
             //For string result we send it like 'message'
             $messageText = $response->data;
         } elseif ($response->getIsClientError() && isset($response->data['message'])) {
             //For HttpExceptions we save message field only to 'message'
             $messageText = $response->data['message'];
             unset($response->data['message']);
             $result->appendChild($response->data);
         } else {
             //Otherwise send all as result
             $result->appendChild($response->data);
         }
         if ($messageText !== '') {
             $message = new DOMElement($this->itemTag);
             $message->appendChild($messageText);
             $root->appendChild($message);
         }
         $root->appendChild($result);
         $root->appendChild($code);
         $root->appendChild($status);
         $this->buildXml($root, $response->data);
         $response->content = $dom->saveXML();
     }
 }
开发者ID:bolom009,项目名称:staging,代码行数:48,代码来源:XmlResponseFormatter.php

示例14: createFromBuffer

 /**
  * @param int $status_code OPTIONAL Defaults to `200`.
  * @param boolean $read_all_buffers OPTIONAL Whether to get and clean the content of all open buffers.
  *                                  Defaults to `true`.
  */
 public static function createFromBuffer($status_code = 200, $read_all_buffers = true)
 {
     # Get our body from the buffer
     $body = "";
     while (($more_body = ob_get_clean()) !== false) {
         $body .= $more_body;
         if (!$read_all_buffers) {
             break;
         }
     }
     $response = new Response($body, $status_code);
     # Add all headers in the buffer and guess response encoding.
     $response->addSentHeaders();
     foreach ($response->getHeaders() as $header) {
         if (preg_match("/^Content-Type:.+;\\s*charset=(.+)\$/i", $header, $matches) === 0) {
             continue;
         }
         $response->setEncoding($matches[1]);
     }
     return $response;
 }
开发者ID:reprovinci,项目名称:satchmo.php-lib,代码行数:26,代码来源:Response.php

示例15: testConstructHeaders

 public function testConstructHeaders()
 {
     $response = new Response(["test" => ["value"]]);
     $this->assertEquals(["test" => ["value"]], $response->getHeaders());
 }
开发者ID:fabyscore,项目名称:fabyscore-lib,代码行数:5,代码来源:ResponseTest.php


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