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


PHP ResponseInterface::getHeaders方法代码示例

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


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

示例1: sendHeaders

 private function sendHeaders()
 {
     foreach ($this->response->getHeaders() as $name => $values) {
         foreach ($values as $value) {
             header($name . ': ' . $value);
         }
     }
 }
开发者ID:ThrusterIO,项目名称:http-response,代码行数:8,代码来源:ResponseSender.php

示例2: _getResult

 /**
  * @param ResponseInterface $response
  *
  * @return ApiResult
  */
 protected function _getResult($response)
 {
     if (!$response instanceof ResponseInterface) {
         throw new \InvalidArgumentException("{$response} should be an instance of ResponseInterface");
     }
     $result = new ApiResult();
     $result->setStatusCode($response->getStatusCode());
     $callId = $response->getHeader('X-Call-Id');
     if (!empty($callId)) {
         $result->setCallId($callId);
     }
     $decoded = json_decode((string) $response->getBody());
     if (isset($decoded->meta) && isset($decoded->data) && isset($decoded->meta->code) && $decoded->meta->code == $response->getStatusCode()) {
         $meta = $decoded->meta;
         $data = $decoded->data;
         if (isset($meta->message)) {
             $result->setStatusMessage($meta->message);
         }
         $result->setContent(json_encode($data));
     } else {
         $result->setContent((string) $response->getBody());
     }
     $result->setHeaders($response->getHeaders());
     return $result;
 }
开发者ID:fortifi,项目名称:api,代码行数:30,代码来源:Guzzle6Connection.php

示例3: send

 /**
  * @param ResponseInterface $response
  */
 public function send(ResponseInterface $response)
 {
     /**
      * build response header
      */
     foreach ($response->getHeaders() as $key => $value) {
         $filter_header = function ($header) {
             $filtered = str_replace('-', ' ', $header);
             $filtered = ucwords($filtered);
             return str_replace(' ', '-', $filtered);
         };
         $name = $filter_header($key);
         foreach ($value as $v) {
             $this->app['SwooleResponder']->header($name, $v);
         }
     }
     /**
      * compress content
      */
     if (!empty($this->app['Config']['server.gzip'])) {
         $this->app['SwooleResponder']->gzip($this->app['Config']['server.gzip']);
     }
     $this->app['SwooleResponder']->status($response->getStatusCode());
     $this->app['SwooleResponder']->header('Server', 'vinnige-app-server');
     $this->app['SwooleResponder']->end((string) $response->getBody());
 }
开发者ID:praswicaksono,项目名称:Vinnige,代码行数:29,代码来源:ServerResponder.php

示例4: leave

 /**
  * Stops the profiling.
  * @param ResponseInterface $response
  */
 public function leave(ResponseInterface $response = null)
 {
     $this->ends = ['wt' => microtime(true), 'mu' => memory_get_usage(), 'pmu' => memory_get_peak_usage()];
     if ($response) {
         $this->response = ['headers' => $response->getHeaders(), 'statusCode' => $response->getStatusCode(), 'body' => (string) $response->getBody()];
     }
 }
开发者ID:sphereio,项目名称:commercetools-php-symfony,代码行数:11,代码来源:Profile.php

示例5: logResponse

 /**
  * @param ResponseInterface $response
  * @param string $type
  */
 protected function logResponse(ResponseInterface $response, $type = 'http')
 {
     $args = [ucfirst($type), $response->getStatusCode(), $response->getReasonPhrase()];
     /** @noinspection PrintfScanfArgumentsInspection */
     $this->log(sprintf(' <== (%s) %s %s', ...$args));
     $headers = $this->removeTokenFromLogs($response->getHeaders());
     $this->log('  Response headers: ' . json_encode($headers), Logger::DEBUG);
 }
开发者ID:SerafimArts,项目名称:gitter-api,代码行数:12,代码来源:IoLoggableTrait.php

示例6: psr7HeadersToString

 /**
  * Convert the PSR-7 headers to string
  *
  * @param ResponseInterface $psr7Response
  * @return string
  */
 private static function psr7HeadersToString(ResponseInterface $psr7Response)
 {
     $headers = '';
     foreach ($psr7Response->getHeaders() as $name => $value) {
         $headers .= $name . ": " . implode(", ", $value) . "\r\n";
     }
     return $headers;
 }
开发者ID:MidnightDesign,项目名称:zend-psr7bridge,代码行数:14,代码来源:Psr7Response.php

示例7: formatResponse

 public function formatResponse(ResponseInterface $response)
 {
     $format = ['code' => $response->getStatusCode(), 'headers' => $response->getHeaders(), 'body' => (string) $response->getBody()];
     if ($this->markerHeader) {
         $format['headers']['X-Guzzle-Stereo'] = true;
     }
     return $format;
 }
开发者ID:ikwattro,项目名称:guzzle-stereo,代码行数:8,代码来源:ResponseFormatter.php

示例8: formatResponse

 /**
  * {@inheritdoc}
  */
 public function formatResponse(ResponseInterface $response)
 {
     $message = sprintf("HTTP/%s %s %s\n", $response->getProtocolVersion(), $response->getStatusCode(), $response->getReasonPhrase());
     foreach ($response->getHeaders() as $name => $values) {
         $message .= $name . ': ' . implode(', ', $values) . "\n";
     }
     return $this->addBody($response, $message);
 }
开发者ID:php-http,项目名称:message,代码行数:11,代码来源:FullHttpMessageFormatter.php

示例9: save

 /**
  * Save data
  *
  * @author  Florian Preusner
  * @version 2.1
  * @since   2015-05
  *
  * @param   ResponseInterface $response
  */
 public function save(ResponseInterface $response)
 {
     $this->setStatusCode($response->getStatusCode());
     $this->setStatusPhrase($response->getReasonPhrase());
     $this->setBody($response->getBody()->__toString());
     $this->setHeaders($response->getHeaders());
     $this->setProtocolVersion($response->getProtocolVersion());
 }
开发者ID:asprega,项目名称:GuzzleBundle,代码行数:17,代码来源:LogResponse.php

示例10: send

 /**
  * @param ResponseInterface $response
  */
 public function send(ResponseInterface $response)
 {
     header('HTTP/' . $response->getProtocolVersion() . ' ' . $response->getStatusCode() . ' ' . $response->getReasonPhrase());
     foreach ($response->getHeaders() as $header => $values) {
         header($header . ': ' . implode(', ', $values));
     }
     parent::send($response);
 }
开发者ID:linpax,项目名称:microphp-framework,代码行数:11,代码来源:MvcApplication.php

示例11: getHeadersAsString

 /**
  * Returns the Guzzle array of headers as a string.
  *
  * @param ResponseInterface $response The Guzzle response.
  *
  * @return string
  */
 public function getHeadersAsString(ResponseInterface $response)
 {
     $headers = $response->getHeaders();
     $rawHeaders = [];
     foreach ($headers as $name => $values) {
         $rawHeaders[] = $name . ": " . implode(", ", $values);
     }
     return implode("\r\n", $rawHeaders);
 }
开发者ID:airbrake,项目名称:phpbrake,代码行数:16,代码来源:GuzzleClient.php

示例12: createResponse

 /**
  * {@inheritdoc}
  */
 public function createResponse(ResponseInterface $psrResponse)
 {
     $response = new Response($psrResponse->getBody()->__toString(), $psrResponse->getStatusCode(), $psrResponse->getHeaders());
     $response->setProtocolVersion($psrResponse->getProtocolVersion());
     foreach ($psrResponse->getHeader('Set-Cookie') as $cookie) {
         $response->headers->setCookie($this->createCookie($cookie));
     }
     return $response;
 }
开发者ID:papillon-cendre,项目名称:d8,代码行数:12,代码来源:HttpFoundationFactory.php

示例13: emitHeaders

 private function emitHeaders(ResponseInterface $response)
 {
     foreach ($response->getHeaders() as $header => $values) {
         $name = str_replace(' ', '-', ucwords(str_replace('-', ' ', $header)));
         foreach ($values as $value) {
             $this->output->writeln(sprintf('%s: %s', $name, $value));
         }
     }
 }
开发者ID:spajak,项目名称:flow,代码行数:9,代码来源:ConsoleEmitter.php

示例14: __construct

 /**
  * Response constructor.
  *
  * @param ResponseInterface $response
  */
 public function __construct($response)
 {
     if ($response instanceof ResponseInterface) {
         $this->statusCode = $response->getStatusCode();
         $this->body = $response->getBody();
         $this->headers = $response->getHeaders();
     }
     $this->decodedBody = json_decode($this->body, true);
 }
开发者ID:mdzzohrabi,项目名称:telegram-sdk,代码行数:14,代码来源:Response.php

示例15: __construct

 /**
  * Constructs a representable document
  *
  * @param ResponseInterface $response
  */
 public function __construct(ResponseInterface $response)
 {
     $headers = $response->getHeaders();
     // What better to get the mime type than what the Telegram servers already send us?
     $this->mime_type = $headers['Content-Type'][0];
     // Same with file length
     $this->file_size = (int) $headers['Content-Length'][0];
     $this->contents = (string) $response->getBody();
 }
开发者ID:unreal4u,项目名称:telegram-api,代码行数:14,代码来源:TelegramDocument.php


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