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


PHP ResponseInterface::getHeaders方法代码示例

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


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

示例1: isError

 protected function isError(ResponseInterface $response)
 {
     if (\array_get($response->getHeaders(), 'RETS-Error', [null])[0] == 1) {
         return true;
     }
     $content_type = \array_get($response->getHeaders(), 'Content-Type', [null])[0];
     if ($content_type and strpos($content_type, 'xml') !== false) {
         return true;
     }
     return false;
 }
开发者ID:mitchlayzell,项目名称:PHRETS,代码行数:11,代码来源:Single.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,代码来源:Guzzle5Connection.php

示例3: formatHeaders

 /**
  * @param RequestInterface|ResponseInterface $message
  * @return string
  */
 protected function formatHeaders($message)
 {
     $headers = [];
     foreach ($message->getHeaders() as $header => $value) {
         $headers[] = sprintf('%s: %s', $header, implode("\n  : ", $value));
     }
     return implode("\n", $headers);
 }
开发者ID:glooby,项目名称:debug-bundle,代码行数:12,代码来源:AbstractMessageFormatter.php

示例4: 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:vihoangson,项目名称:Family,代码行数:16,代码来源:FacebookGuzzleHttpClient.php

示例5: createResponse

 /**
  * Create the response object
  *
  * @param  ResponseInterface         $adapterResponse
  * @return \Tmdb\HttpClient\Response
  */
 private function createResponse(ResponseInterface $adapterResponse = null)
 {
     $response = new Response();
     if ($adapterResponse !== null) {
         $response->setCode($adapterResponse->getStatusCode());
         $response->setHeaders(new ParameterBag($adapterResponse->getHeaders()));
         $response->setBody((string) $adapterResponse->getBody());
     }
     return $response;
 }
开发者ID:gunnartorfis,项目名称:plex_requests,代码行数:16,代码来源:GuzzleAdapter.php

示例6: save

 public function save(RequestInterface $request, ResponseInterface $response)
 {
     $ttl = (int) $request->getConfig()->get('cache.ttl');
     $key = $this->getCacheKey($request);
     // Persist the response body if needed
     if ($response->getBody() && $response->getBody()->getSize() > 0) {
         $this->cache->save($key, array('code' => $response->getStatusCode(), 'headers' => $response->getHeaders(), 'body' => (string) $response->getBody()), $ttl);
         $request->getConfig()->set('cache.key', $key);
     }
 }
开发者ID:QSimon,项目名称:CsaGuzzleBundle,代码行数:10,代码来源:CacheStorage.php

示例7: parseMetadata

 public function parseMetadata(ResponseInterface $response)
 {
     $metadata = [];
     foreach ($response->getHeaders() as $header => $value) {
         $position = strpos($header, static::METADATA_PREFIX);
         if ($position === 0) {
             $metadata[ltrim($header, static::METADATA_PREFIX)] = $response->getHeader($header);
         }
     }
     return $metadata;
 }
开发者ID:boxrice007,项目名称:openstack,代码行数:11,代码来源:MetadataTrait.php

示例8: assertResponseMatch

 /**
  * Asserts response match with the response schema.
  *
  * @param ResponseInterface $response
  * @param SchemaManager $schemaManager
  * @param string $path percent-encoded path used on the request.
  * @param string $httpMethod
  * @param string $message
  */
 public function assertResponseMatch(ResponseInterface $response, SchemaManager $schemaManager, $path, $httpMethod, $message = '')
 {
     $this->assertResponseMediaTypeMatch($response->getHeader('Content-Type'), $schemaManager, $path, $httpMethod, $message);
     $httpCode = $response->getStatusCode();
     $headers = $response->getHeaders();
     foreach ($headers as &$value) {
         $value = implode(', ', $value);
     }
     $this->assertResponseHeadersMatch($headers, $schemaManager, $path, $httpMethod, $httpCode, $message);
     $this->assertResponseBodyMatch($response->json(['object' => true]), $schemaManager, $path, $httpMethod, $httpCode, $message);
 }
开发者ID:Beanhunter,项目名称:SwaggerAssertions,代码行数:20,代码来源:GuzzleAssertsTrait.php

示例9: extractHeaders

 /**
  * Extract a map of headers with an optional prefix from the response.
  */
 private function extractHeaders($name, Shape $shape, ResponseInterface $response, &$result)
 {
     // Check if the headers are prefixed by a location name
     $result[$name] = [];
     $prefix = $shape['locationName'];
     $prefixLen = strlen($prefix);
     foreach ($response->getHeaders() as $k => $values) {
         if (!$prefixLen) {
             $result[$name][$k] = implode(', ', $values);
         } elseif (stripos($k, $prefix) === 0) {
             $result[$name][substr($k, $prefixLen)] = implode(', ', $values);
         }
     }
 }
开发者ID:briareos,项目名称:aws-sdk-php,代码行数:17,代码来源:AbstractRestParser.php

示例10: validateResponse

 /**
  * Validate the response.
  *
  * @return $this
  */
 protected function validateResponse()
 {
     $body = $this->request->getBody();
     $this->response = $body->getContents();
     // Send new request
     if ($this->request == false || $this->request->getReasonPhrase() != 'OK') {
         $this->objDebug->addDebug("Request", substr($this->response, 0, 4096));
         $this->objDebug->addDebug("Error Response", substr($this->response, 0, 4096));
         throw new \RuntimeException("Error on transmission, with message: " . $this->request->getStatusCode());
     }
     $this->objDebug->addDebug("Request", substr($this->response, 0, 4096));
     // Build response Header information.
     $strResponseHeader = "";
     $arrHeaderKeys = array_keys($this->request->getHeaders());
     foreach ($arrHeaderKeys as $keyHeader) {
         $strResponseHeader .= $keyHeader . ": " . $this->request->getHeader($keyHeader) . "\n";
     }
     $this->objDebug->addDebug("Response", $strResponseHeader . "\n\n" . $this->request->getBody()->read(2048));
     // Check if we have a response
     if (strlen($this->response) == 0) {
         throw new \RuntimeException("We got a blank response from server.");
     }
     // Check for "Fatal error" on client side
     if (strpos($this->response, "Fatal error") !== false) {
         throw new \RuntimeException("We got a Fatal error on client site. " . $this->response);
     }
     // Check for "Warning" on client side
     if (strpos($this->response, "Warning") !== false) {
         $intStart = stripos($this->response, "<strong>Warning</strong>:");
         $intEnd = stripos($this->response, "on line");
         if ($intEnd === false) {
             $intLength = strlen($this->response) - $intStart;
         } else {
             $intLength = $intEnd - $intStart;
         }
         throw new \RuntimeException("We got a Warning on client site.<br /><br />" . substr($this->response, $intStart, $intLength));
     }
     return $this;
 }
开发者ID:menatwork,项目名称:ctocommunication,代码行数:44,代码来源:Server.php

示例11: headers

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

示例12: convertResponse

 /**
  * Conver the Guzzle response to a Symfony response.
  *
  * @param  ResponseInterface $response
  * @return Response
  */
 protected function convertResponse(ResponseInterface $response)
 {
     return new Response($response->getBody(), $response->getStatusCode(), $response->getHeaders());
 }
开发者ID:Creare,项目名称:CreareProxy,代码行数:10,代码来源:GuzzleAdapter.php

示例13: getBodyContent

 /**
  * @param \GuzzleHttp\Message\ResponseInterface $response
  *
  * @return array
  */
 protected function getBodyContent(ResponseInterface $response)
 {
     $body = $response->getBody();
     $headers = $response->getHeaders();
     return $this->createContent($headers, $body);
 }
开发者ID:php-riak,项目名称:riak-client,代码行数:11,代码来源:BaseHttpStrategy.php

示例14: __construct

 public function __construct(HttpResponseInterface $response)
 {
     $this->_statusCode = $response->getStatusCode();
     $this->_headers = $response->getHeaders();
     $this->_body = $response->json();
 }
开发者ID:VirgilSecurity,项目名称:virgil-sdk-php,代码行数:6,代码来源:Response.php

示例15: createResponse

 /**
  * Converts a Guzzle response into a PSR response.
  *
  * @param GuzzleResponse $response
  *
  * @return ResponseInterface
  */
 private function createResponse(GuzzleResponse $response)
 {
     $body = $response->getBody();
     return $this->messageFactory->createResponse($response->getStatusCode(), null, $response->getHeaders(), isset($body) ? $body->detach() : null, $response->getProtocolVersion());
 }
开发者ID:parsingeye,项目名称:guzzle5-adapter,代码行数:12,代码来源:Guzzle5HttpAdapter.php


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