當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。