當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Response::getHeader方法代碼示例

本文整理匯總了PHP中Guzzle\Http\Message\Response::getHeader方法的典型用法代碼示例。如果您正苦於以下問題:PHP Response::getHeader方法的具體用法?PHP Response::getHeader怎麽用?PHP Response::getHeader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Guzzle\Http\Message\Response的用法示例。


在下文中一共展示了Response::getHeader方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: getRateReset

 /**
  * Seconds remaining until a new time window opens
  *
  * @return null
  */
 public function getRateReset()
 {
     if (!$this->lastResponse) {
         return null;
     }
     /** @var Header $limit */
     $limit = $this->lastResponse->getHeader('X-Rate-Reset');
     return $limit ? $limit->normalize() : null;
 }
開發者ID:javihgil,項目名稱:genderize-io-client,代碼行數:14,代碼來源:GenderizeClient.php

示例2: testOnRequestSuccess

 public function testOnRequestSuccess()
 {
     $event = new Event();
     $response = new Response(200, array('X-RateLimit-Limit' => array(30), 'X-RateLimit-Remaining' => array(29), 'X-RateLimit-Reset' => array(10)));
     $event['response'] = $response;
     $plugin = new RateLimitPlugin();
     $plugin->onRequestSuccess($event);
     $this->assertAttributeEquals((string) $response->getHeader('X-RateLimit-Limit'), 'rateLimitMax', $plugin);
     $this->assertAttributeEquals((string) $response->getHeader('X-RateLimit-Remaining'), 'rateLimitRemaining', $plugin);
     $this->assertAttributeEquals((string) $response->getHeader('X-RateLimit-Reset'), 'rateLimitReset', $plugin);
     $this->assertAttributeEquals(true, 'rateLimitEnabled', $plugin);
 }
開發者ID:opdavies,項目名稱:nwdrupalwebsite,代碼行數:12,代碼來源:RateLimitPluginTest.php

示例3: getLatestResponseHeaders

 /**
  * {@inheritdoc}
  */
 public function getLatestResponseHeaders()
 {
     if (null === $this->response) {
         return;
     }
     return ['reset' => (int) (string) $this->response->getHeader('RateLimit-Reset'), 'remaining' => (int) (string) $this->response->getHeader('RateLimit-Remaining'), 'limit' => (int) (string) $this->response->getHeader('RateLimit-Limit')];
 }
開發者ID:skaisser,項目名稱:upcloud,代碼行數:10,代碼來源:GuzzleAdapter.php

示例4: getApiLimit

 public static function getApiLimit(Response $response)
 {
     $remainingCalls = $response->getHeader('X-RateLimit-Remaining');
     if (null !== $remainingCalls && 1 > $remainingCalls) {
         throw new ApiLimitExceedException($remainingCalls);
     }
 }
開發者ID:alnutile,項目名稱:saucelabs_client,代碼行數:7,代碼來源:ResponseMediator.php

示例5: cache

 public function cache(RequestInterface $request, Response $response)
 {
     $currentTime = time();
     $ttl = $request->getParams()->get('cache.override_ttl') ?: $response->getMaxAge() ?: $this->defaultTtl;
     if ($cacheControl = $response->getHeader('Cache-Control')) {
         $stale = $cacheControl->getDirective('stale-if-error');
         $ttl += $stale == true ? $ttl : $stale;
     }
     // Determine which manifest key should be used
     $key = $this->getCacheKey($request);
     $persistedRequest = $this->persistHeaders($request);
     $entries = array();
     if ($manifest = $this->cache->fetch($key)) {
         // Determine which cache entries should still be in the cache
         $vary = $response->getVary();
         foreach (unserialize($manifest) as $entry) {
             // Check if the entry is expired
             if ($entry[4] < $currentTime) {
                 continue;
             }
             $entry[1]['vary'] = isset($entry[1]['vary']) ? $entry[1]['vary'] : '';
             if ($vary != $entry[1]['vary'] || !$this->requestsMatch($vary, $entry[0], $persistedRequest)) {
                 $entries[] = $entry;
             }
         }
     }
     // Persist the response body if needed
     $bodyDigest = null;
     if ($response->getBody() && $response->getBody()->getContentLength() > 0) {
         $bodyDigest = $this->getBodyKey($request->getUrl(), $response->getBody());
         $this->cache->save($bodyDigest, (string) $response->getBody(), $ttl);
     }
     array_unshift($entries, array($persistedRequest, $this->persistHeaders($response), $response->getStatusCode(), $bodyDigest, $currentTime + $ttl));
     $this->cache->save($key, serialize($entries));
 }
開發者ID:diandianxiyu,項目名稱:Yii2Api,代碼行數:35,代碼來源:DefaultCacheStorage.php

示例6: validateResponse

 /**
  * Validate the HTTP response and throw exceptions on errors
  *
  * @throws ServerException
  */
 private function validateResponse()
 {
     if ($this->httpResponse->getStatusCode() !== 200) {
         $statusCode = $this->httpResponse->getStatusCode();
         throw new ServerException('Server responded with HTTP status ' . $statusCode, $statusCode);
     } else {
         if (strpos($this->httpResponse->getHeader('Content-Type'), 'application/json') === false) {
             throw new ServerException('Server did not respond with the expected content-type (application/json)');
         }
     }
     try {
         $this->httpResponse->json();
     } catch (RuntimeException $e) {
         throw new ServerException($e->getMessage());
     }
 }
開發者ID:nexxome,項目名稱:html-validator,代碼行數:21,代碼來源:Response.php

示例7: parseHeaders

 /**
  * Parses additional exception information from the response headers
  *
  * @param RequestInterface $request  Request that was issued
  * @param Response         $response The response from the request
  * @param array            $data     The current set of exception data
  */
 protected function parseHeaders(RequestInterface $request, Response $response, array &$data)
 {
     $data['message'] = $response->getStatusCode() . ' ' . $response->getReasonPhrase();
     if ($requestId = $response->getHeader('x-amz-request-id')) {
         $data['request_id'] = $requestId;
         $data['message'] .= " (Request-ID: {$requestId})";
     }
 }
開發者ID:skinnard,項目名稱:FTL-2,代碼行數:15,代碼來源:DefaultXmlExceptionParser.php

示例8: decode

 public static function decode(Response $response)
 {
     if (strpos($response->getHeader(Header::CONTENT_TYPE), Mime::JSON) !== false) {
         $string = (string) $response->getBody();
         $response = json_decode($string);
         self::checkJsonError($string);
         return $response;
     }
 }
開發者ID:etaoins,項目名稱:php-opencloud,代碼行數:9,代碼來源:Formatter.php

示例9: getDelay

 /**
  * {@inheritdoc}
  */
 protected function getDelay($retries, RequestInterface $request, Response $response = null, HttpException $e = null)
 {
     if ($response) {
         // Validate the checksum against our computed checksum
         if ($checksum = (string) $response->getHeader('x-amz-crc32')) {
             // Retry the request if the checksums don't match, otherwise, return null
             return $checksum != hexdec(Stream::getHash($response->getBody(), 'crc32b')) ? true : null;
         }
     }
 }
開發者ID:romainneutron,項目名稱:aws-sdk-php,代碼行數:13,代碼來源:Crc32ErrorChecker.php

示例10: getDelay

 protected function getDelay($retries, RequestInterface $request, Response $response = null, HttpException $e = null)
 {
     if ($response) {
         //Short circuit the rest of the checks if it was successful
         if ($response->isSuccessful()) {
             return false;
         } else {
             if (isset($this->errorCodes[$response->getStatusCode()])) {
                 if ($response->getHeader("Retry-After")) {
                     return $response->getHeader("Retry-After")->__toString();
                 } else {
                     return self::$defaultRetryAfter;
                 }
             } else {
                 return null;
             }
         }
     }
 }
開發者ID:keboola,項目名稱:provisioning-client,代碼行數:19,代碼來源:MaintenanceBackoffStrategy.php

示例11: parse

 /**
  * {@inheritdoc}
  */
 public function parse(Response $response)
 {
     $data = array('code' => null, 'message' => null, 'type' => $response->isClientError() ? 'client' : 'server', 'request_id' => (string) $response->getHeader('x-amzn-RequestId'), 'parsed' => null);
     if (null !== ($json = json_decode($response->getBody(true), true))) {
         $data['parsed'] = $json;
         $json = array_change_key_case($json);
         $data = $this->doParse($data, $json);
     }
     return $data;
 }
開發者ID:romainneutron,項目名稱:aws-sdk-php,代碼行數:13,代碼來源:AbstractJsonExceptionParser.php

示例12: getContextFromResponse

 private function getContextFromResponse(Response $response)
 {
     $extraFields = array();
     $headersToLookFor = array('x-served-by', 'x-backend', 'x-location', 'x-varnish');
     foreach ($headersToLookFor as $headerName) {
         if ($response->hasHeader($headerName)) {
             $extraFields[$headerName] = (string) $response->getHeader($headerName);
         }
     }
     return $extraFields;
 }
開發者ID:robertpisano,項目名稱:LeeLee,代碼行數:11,代碼來源:MonologGuzzleLogAdapter.php

示例13: factory

 public static function factory(RequestInterface $request, Response $response)
 {
     $label = 'Bearer error response';
     $bearerReason = self::headerToReason($response->getHeader("WWW-Authenticate"));
     $message = $label . PHP_EOL . implode(PHP_EOL, array('[status code] ' . $response->getStatusCode(), '[reason phrase] ' . $response->getReasonPhrase(), '[bearer reason] ' . $bearerReason, '[url] ' . $request->getUrl()));
     $e = new static($message);
     $e->setResponse($response);
     $e->setRequest($request);
     $e->setBearerReason($bearerReason);
     return $e;
 }
開發者ID:Farik2605,項目名稱:tobi,代碼行數:11,代碼來源:BearerErrorResponseException.php

示例14: getBackoffPeriod

 /**
  * Get the amount of time to delay in seconds before retrying a request
  *
  * @param int              $retries  Number of retries of the request
  * @param RequestInterface $request  Request that was sent
  * @param Response         $response Response that was received. Note that there may not be a response
  * @param HttpException    $e        Exception that was encountered if any
  *
  * @return bool|int Returns false to not retry or the number of seconds to delay between retries
  */
 public function getBackoffPeriod($retries, RequestInterface $request, Response $response = null, HttpException $e = null)
 {
     if (!$response) {
         return false;
     }
     if ($response->getStatusCode() != 429) {
         return false;
     }
     $reset = (string) $response->getHeader('X-Rate-Limit-Reset');
     if (!preg_match('/^[0-9]+$/', $reset)) {
         return false;
     }
     return ((int) $reset + 0.1) * $this->getMultiplier();
 }
開發者ID:dh-open,項目名稱:desk-php,代碼行數:24,代碼來源:Strategy.php

示例15: doParse

 /**
  * {@inheritdoc}
  */
 protected function doParse(array $data, Response $response)
 {
     // Merge in error data from the JSON body
     if ($json = $data['parsed']) {
         $data = array_replace($data, $json);
     }
     // Correct error type from services like Amazon Glacier
     if (!empty($data['type'])) {
         $data['type'] = strtolower($data['type']);
     }
     // Retrieve the error code from services like Amazon Elastic Transcoder
     if ($code = (string) $response->getHeader('x-amzn-ErrorType')) {
         $data['code'] = substr($code, 0, strpos($code, ':'));
     }
     return $data;
 }
開發者ID:ebeauchamps,項目名稱:brilliantretail,代碼行數:19,代碼來源:JsonRestExceptionParser.php


注:本文中的Guzzle\Http\Message\Response::getHeader方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。