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


PHP Response::getHeaders方法代码示例

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


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

示例1: deduce

 /**
  * @return ErrorResponse|SuccessResponse
  */
 public function deduce()
 {
     /* @var array $response */
     $response = (array) $this->response->json();
     if (array_key_exists('type', $response) && $response['type'] === 'error') {
         return new ErrorResponse($this->response->getStatusCode(), $this->response->getHeaders(), $this->response->getBody());
     }
     return new SuccessResponse($this->response->getStatusCode(), $this->response->getHeaders(), $this->response->getBody());
 }
开发者ID:mahsanamin,项目名称:box-php-sdk,代码行数:12,代码来源:Response.php

示例2: __construct

 /**
  * Constructor
  *
  * @param GuzzleResponse $response
  */
 public function __construct(GuzzleResponse $response)
 {
     $headers = $response->getHeaders();
     //-- this is a hack on my part and I'm terribly sorry it exists
     //-- but deal with it.
     foreach ($headers as $header => $value) {
         $this->headers[$header] = implode(',', array_values((array) $value));
     }
     $this->url = $response->getEffectiveUrl();
     $url_parts = explode('?', $this->url);
     if (isset($url_parts[1])) {
         $query = explode('&', $url_parts[1]);
         foreach ($query as $params) {
             $kv = explode('=', $params);
             $this->params[$kv[0]] = isset($kv[1]) ? $kv[1] : '';
         }
     }
     // $this->params = $response->request_parameters;
     // $this->method = $response->request_method;
     $this->json = $response->json();
     // $json = json_decode($this->json, TRUE);
     $this->data = isset($this->json['data']) ? $this->json['data'] : [];
     $this->meta = isset($this->json['meta']) ? $this->json['meta'] : [];
     if (isset($this->json['code']) && $this->json['code'] !== 200) {
         $this->meta = $this->json;
     }
     $this->pagination = isset($this->json['pagination']) ? $this->json['pagination'] : [];
     $this->user = isset($this->json['user']) ? $this->json['user'] : [];
     $this->access_token = isset($this->json['access_token']) ? $this->json['access_token'] : NULL;
     $this->limit = isset($this->headers[self::RATE_LIMIT_HEADER]) ? $this->headers[self::RATE_LIMIT_HEADER] : 0;
     $this->remaining = isset($this->headers[self::RATE_LIMIT_REMAINING_HEADER]) ? $this->headers[self::RATE_LIMIT_REMAINING_HEADER] : 0;
 }
开发者ID:delta98,项目名称:Instaphp,代码行数:37,代码来源:Response.php

示例3: lastResponseHeaders

 /**
  * Returns the SOAP headers from the last response.
  *
  * @return mix The last SOAP response headers.
  */
 public function lastResponseHeaders()
 {
     if ($this->response instanceof Response) {
         return $this->response->getHeaders();
     }
     return [];
 }
开发者ID:zimbra-api,项目名称:soap,代码行数:12,代码来源:Http.php

示例4: createResponse

 /**
  * Taken from Mink\BrowserKitDriver
  *
  * @param Response $response
  *
  * @return \Symfony\Component\BrowserKit\Response
  */
 protected function createResponse(Response $response)
 {
     $contentType = $response->getHeader('Content-Type');
     $matches = null;
     if (!$contentType or strpos($contentType, 'charset=') === false) {
         $body = $response->getBody(true);
         if (preg_match('/\\<meta[^\\>]+charset *= *["\']?([a-zA-Z\\-0-9]+)/i', $body, $matches)) {
             $contentType .= ';charset=' . $matches[1];
         }
         $response->setHeader('Content-Type', $contentType);
     }
     $headers = $response->getHeaders();
     $status = $response->getStatusCode();
     $matchesMeta = null;
     $matchesHeader = null;
     $isMetaMatch = preg_match('/\\<meta[^\\>]+http-equiv="refresh" content="(\\d*)\\s*;?\\s*url=(.*?)"/i', $response->getBody(true), $matchesMeta);
     $isHeaderMatch = preg_match('~(\\d*);?url=(.*)~', (string) $response->getHeader('Refresh'), $matchesHeader);
     $matches = $isMetaMatch ? $matchesMeta : $matchesHeader;
     if (!empty($matches) && (empty($matches[1]) || $matches[1] < $this->refreshMaxInterval)) {
         $uri = $this->getAbsoluteUri($matches[2]);
         $partsUri = parse_url($uri);
         $partsCur = parse_url($this->getHistory()->current()->getUri());
         foreach ($partsCur as $key => $part) {
             if ($key === 'fragment') {
                 continue;
             }
             if (!isset($partsUri[$key]) || $partsUri[$key] !== $part) {
                 $status = 302;
                 $headers['Location'] = $uri;
                 break;
             }
         }
     }
     return new BrowserKitResponse($response->getBody(), $status, $headers);
 }
开发者ID:itillawarra,项目名称:cmfive,代码行数:42,代码来源:Guzzle.php

示例5:

 /**
  * @param \GuzzleHttp\Message\Response $response
  */
 function __construct($response)
 {
     parent::__construct($response->getStatusCode(), $response->getHeaders(), $response->getBody());
     $jsonBody = $this->json();
     if (array_key_exists("code", $jsonBody)) {
         $this->internal_code = $jsonBody["code"];
         $this->internal_message = $jsonBody["message"];
         $this->internal_type = $jsonBody["type"];
     }
     if (array_key_exists("atoken", $jsonBody) || array_key_exists("uid", $jsonBody)) {
         $this->internal_code = 200;
         $this->internal_type = $jsonBody["type"] = "oauthResponse";
     }
 }
开发者ID:dnocode,项目名称:doisdk,代码行数:17,代码来源:OAuth2Response.php

示例6: createResponseFromGuzzleResponse

 /**
  * @param GuzzleResponse $guzzleResponse
  *
  * @return Response
  */
 protected function createResponseFromGuzzleResponse(GuzzleResponse $guzzleResponse)
 {
     $content = null;
     if ($guzzleResponse->getBody() !== null) {
         $content = $guzzleResponse->getBody()->getContents();
     }
     $response = new Response($content, $guzzleResponse->getStatusCode());
     $response->setHeaders($guzzleResponse->getHeaders());
     $deniedHeaders = array('transfer-encoding', 'x-powered-by', 'content-length', 'content-encoding');
     foreach ($deniedHeaders as $headerName) {
         $response->removeHeader($headerName);
     }
     return $response;
 }
开发者ID:phpextra,项目名称:proxy,代码行数:19,代码来源:Guzzle4Adapter.php

示例7: testDoesTheSameAsResponseWhenDereferenced

 public function testDoesTheSameAsResponseWhenDereferenced()
 {
     $str = Stream::factory('foo');
     $response = new Response(200, ['Foo' => 'bar'], $str);
     $future = MockTest::createFuture(function () use($response) {
         return $response;
     });
     $this->assertFalse($this->readAttribute($future, 'isRealized'));
     $this->assertEquals(200, $future->getStatusCode());
     $this->assertTrue($this->readAttribute($future, 'isRealized'));
     // Deref again does nothing.
     $future->wait();
     $this->assertTrue($this->readAttribute($future, 'isRealized'));
     $this->assertEquals('bar', $future->getHeader('Foo'));
     $this->assertEquals(['bar'], $future->getHeaderAsarray('Foo'));
     $this->assertSame($response->getHeaders(), $future->getHeaders());
     $this->assertSame($response->getBody(), $future->getBody());
     $this->assertSame($response->getProtocolVersion(), $future->getProtocolVersion());
     $this->assertSame($response->getEffectiveUrl(), $future->getEffectiveUrl());
     $future->setEffectiveUrl('foo');
     $this->assertEquals('foo', $response->getEffectiveUrl());
     $this->assertSame($response->getReasonPhrase(), $future->getReasonPhrase());
     $this->assertTrue($future->hasHeader('foo'));
     $future->removeHeader('Foo');
     $this->assertFalse($future->hasHeader('foo'));
     $this->assertFalse($response->hasHeader('foo'));
     $future->setBody(Stream::factory('true'));
     $this->assertEquals('true', (string) $response->getBody());
     $this->assertTrue($future->json());
     $this->assertSame((string) $response, (string) $future);
     $future->setBody(Stream::factory('<a><b>c</b></a>'));
     $this->assertEquals('c', (string) $future->xml()->b);
     $future->addHeader('a', 'b');
     $this->assertEquals('b', $future->getHeader('a'));
     $future->addHeaders(['a' => '2']);
     $this->assertEquals('b, 2', $future->getHeader('a'));
     $future->setHeader('a', '2');
     $this->assertEquals('2', $future->getHeader('a'));
     $future->setHeaders(['a' => '3']);
     $this->assertEquals(['a' => ['3']], $future->getHeaders());
 }
开发者ID:hexcode007,项目名称:yfcms,代码行数:41,代码来源:FutureResponseTest.php

示例8: createResponse

 /**
  * Taken from Mink\BrowserKitDriver
  *
  * @param Response $response
  *
  * @return \Symfony\Component\BrowserKit\Response
  */
 protected function createResponse(Response $response)
 {
     $contentType = $response->getHeader('Content-Type');
     if (!$contentType or strpos($contentType, 'charset=') === false) {
         $body = $response->getBody(true);
         if (preg_match('/\\<meta[^\\>]+charset *= *["\']?([a-zA-Z\\-0-9]+)/i', $body, $matches)) {
             $contentType .= ';charset=' . $matches[1];
         }
         $response->setHeader('Content-Type', $contentType);
     }
     $headers = $response->getHeaders();
     $status = $response->getStatusCode();
     if (preg_match('/\\<meta[^\\>]+http-equiv="refresh" content=".*?url=(.*?)"/i', $response->getBody(true), $matches)) {
         $status = 302;
         $headers['Location'] = $matches[1];
     }
     if (preg_match('~url=(.*)~', (string) $response->getHeader('Refresh'), $matches)) {
         $status = 302;
         $headers['Location'] = $matches[1];
     }
     return new BrowserKitResponse($response->getBody(), $status, $headers);
 }
开发者ID:aleguisf,项目名称:fvdev1,代码行数:29,代码来源:Guzzle.php

示例9: getGuzzleResponseData

 /**
  * @param $response HttpResponse
  *
  * @throws ServerException
  */
 private function getGuzzleResponseData($response)
 {
     if (!is_a($response, 'GuzzleHttp\\Message\\Response')) {
         $this->splitResponseToHeadersArrayAndBody($response);
         $response = new Response($this->status, $this->headers, null, []);
         $this->body = (string) $this->body;
         //            $this->status = (int) explode(' ', $this->status)[1];
         $statusLineArray = explode(" ", trim($this->headers['status'][0]));
         $this->status = (int) $statusLineArray[1];
     } else {
         $this->status = $response->getStatusCode();
         $this->body = (string) $response->getBody();
         $response->requestHandler = $this->request->requestHandler;
     }
     $this->headers = $response->getHeaders();
     if ($this->verboseExtractStatusLine === true) {
         $this->getVerboseStatusLine($response);
     }
     if (in_array(intval($this->status), $this->enabledHttpServerExceptions)) {
         $this->getVerboseStatusLine($response);
         throw new ServerException($this->statusPhrase, $this->status);
     }
 }
开发者ID:frankmayer,项目名称:arangodb-php-core-guzzle,代码行数:28,代码来源:HttpResponse.php

示例10: createResponse

 protected function createResponse(GuzzleResponse $response)
 {
     $headers = $response->getHeaders();
     return new Response($response->getBody(true), $response->getStatusCode(), $headers);
 }
开发者ID:b-sebastian,项目名称:timetable,代码行数:5,代码来源:Client.php

示例11: getHeaders

 /**
  * @return array
  */
 public function getHeaders()
 {
     return $this->response->getHeaders();
 }
开发者ID:Kevin-ZK,项目名称:vaneDisk,代码行数:7,代码来源:response.php

示例12: convertResponse

 private static function convertResponse(Response $response)
 {
     $headers = array_map(function ($h) {
         return implode(', ', $h);
     }, $response->getHeaders());
     return ['status' => $response->getStatusCode(), 'reason' => $response->getReasonPhrase(), 'headers' => $headers, 'body' => base64_encode((string) $response->getBody())];
 }
开发者ID:453111208,项目名称:bbc,代码行数:7,代码来源:Server.php

示例13: buildSymfonyResponseFromGuzzleResponse

 /**
  * Convert a Guzzle Response to a Symfony Response
  *
  * @param GuzzleResponse $prerenderedResponse
  * @return SymfonyResponse
  */
 private function buildSymfonyResponseFromGuzzleResponse(GuzzleResponse $prerenderedResponse)
 {
     $body = $prerenderedResponse->getBody();
     $statusCode = $prerenderedResponse->getStatusCode();
     $headers = $prerenderedResponse->getHeaders();
     return new SymfonyResponse($body, $statusCode, $headers);
 }
开发者ID:Halpha,项目名称:Laravel-Prerender,代码行数:13,代码来源:PrerenderMiddleware.php

示例14: hardCheckByHeader

 /**
  * Error check by header
  * @param \GuzzleHttp\Message\Response $metaData
  * @return array
  */
 private function hardCheckByHeader(\GuzzleHttp\Message\Response $metaData)
 {
     $headers = array_change_key_case($metaData->getHeaders());
     $statusCode = (int) $metaData->getStatusCode();
     $isErrorPageCode = ['40x' => [401, 403, 404], '50x' => [500, 502, 503], '30x' => [301, 302, 308]];
     foreach ($isErrorPageCode as $errorType => $statuses) {
         if (in_array($statusCode, $statuses)) {
             return ['result' => false, 'status' => "NG : status code {$errorType}"];
         }
     }
     if ($statusCode === 200 && $statusCode === 304) {
         return ['result' => true];
     }
     if (array_key_exists('content-length', $headers) && $headers['content-length'][0] < $this->contentsSize) {
         return ['result' => false, 'status' => 'NG : contentsSize'];
     }
     return ['result' => true];
 }
开发者ID:bootjp,项目名称:crawler,代码行数:23,代码来源:Checker.php

示例15: proxyResponseHeaders

 /**
  * @param GuzzleHttp\Message\Response
  */
 public function proxyResponseHeaders(Response $response = null)
 {
     if (!$response) {
         return;
     }
     $headers = $response->getHeaders();
     foreach ($headers as $header_name => $header_values) {
         $header_values = is_array($header_values) ? $header_values : (array) $header_values;
         foreach ($header_values as $header_value) {
             // Only attempt proxying when WF protocol is detected
             if ($this->isLineWildfireProtocol($header_name)) {
                 $this->_proxy($header_value);
             }
         }
         // foreach header_values
     }
     // foreach headers
 }
开发者ID:behance,项目名称:guzzle-fireclient,代码行数:21,代码来源:ResponseConsumer.php


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