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


PHP Response::getStatusCode方法代碼示例

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


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

示例1: retryDecider

 static function retryDecider($retries, Request $request, Response $response = null, RequestException $exception = null)
 {
     // Limit the number of retries to 5
     if ($retries >= 5) {
         return false;
     }
     // Retry connection exceptions
     if ($exception instanceof ConnectException) {
         return true;
     }
     if ($response) {
         // Retry on server errors
         if ($response->getStatusCode() >= 500) {
             return true;
         }
         // Retry on rate limits
         if ($response->getStatusCode() == 429) {
             $retryDelay = $response->getHeaderLine('Retry-After');
             if (strlen($retryDelay)) {
                 printf(" retry delay: %d secs\n", (int) $retryDelay);
                 sleep((int) $retryDelay);
                 return true;
             }
         }
     }
     return false;
 }
開發者ID:andig,項目名稱:spotify-web-api-extensions,代碼行數:27,代碼來源:GuzzleClientFactory.php

示例2: setErrorResponse

 /**
  * @param GuzzleException $guzzleException
  */
 public function setErrorResponse(GuzzleException $guzzleException)
 {
     $this->exception = $guzzleException;
     if ($guzzleException instanceof RequestException) {
         $this->response = $guzzleException->getResponse();
         $this->status = $this->response->getStatusCode();
     }
     $this->timeResponse = microtime(true);
 }
開發者ID:FreezyBee,項目名稱:MailChimp,代碼行數:12,代碼來源:Resource.php

示例3: isSuccessful

 /**
  * Check response content is successful or not
  *
  * @return boolean
  */
 public function isSuccessful()
 {
     $statusCode = $this->response->getStatusCode();
     if ($statusCode == self::STATUS_CONSUME_OK || $statusCode == self::STATUS_DELETE_OK || $statusCode == self::STATUS_PRODUCE_OK) {
         return true;
     }
     $this->errorMessage = self::$status[$statusCode];
     return false;
 }
開發者ID:goqihoo,項目名稱:aliyun,代碼行數:14,代碼來源:Response.php

示例4: deduce

 /**
  * @return ErrorResponse|SuccessResponse
  */
 public function deduce()
 {
     /* @var array $response */
     $response = (array) json_decode($this->response->getBody()->getContents());
     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:NeokamiCode,項目名稱:box-php-sdk,代碼行數:12,代碼來源:Response.php

示例5: connect

 /**
  * Connect to server.
  */
 private function connect()
 {
     $headers = [];
     if ($this->lastId) {
         $headers['Last-Event-ID'] = $this->lastId;
     }
     $this->response = $this->client->request('GET', $this->url, ['stream' => true, 'headers' => $headers]);
     if ($this->response->getStatusCode() == 204) {
         throw new RuntimeException('Server forbid connection retry by responding 204 status code.');
     }
 }
開發者ID:obsh,項目名稱:sse-client,代碼行數:14,代碼來源:Client.php

示例6: isJsonResponse

 /**
  * Check if the response given by fcm is parsable
  *
  * @param GuzzleResponse $response
  *
  * @throws InvalidRequestException
  * @throws ServerResponseException
  * @throws UnauthorizedRequestException
  */
 private function isJsonResponse(GuzzleResponse $response)
 {
     if ($response->getStatusCode() == 200) {
         return;
     }
     if ($response->getStatusCode() == 400) {
         throw new InvalidRequestException($response);
     }
     if ($response->getStatusCode() == 401) {
         throw new UnauthorizedRequestException($response);
     }
     throw new ServerResponseException($response);
 }
開發者ID:brozot,項目名稱:laravel-fcm,代碼行數:22,代碼來源:BaseResponse.php

示例7: search

 /**
  * Search book by tags like title, author, publisher etc.
  *
  * @param array $query
  *
  * @return mixed
  */
 public function search(array $query)
 {
     $processed = $this->transformQueryParameters($query, $this->queryTransformationMap());
     $query = implode(' ', $processed[1]);
     foreach ($processed[0] as $key => $value) {
         $query .= ' ' . $key . $value;
     }
     $query = $this->prepareQuery($query);
     $this->response = $this->client->get($query);
     if ($this->response->getStatusCode() != 200) {
         $this->response = null;
     }
     return $this;
 }
開發者ID:znck,項目名稱:livre,代碼行數:21,代碼來源:GoogleBooks.php

示例8: make

 public static function make(Response $response)
 {
     $code = $response->getStatusCode();
     $body = json_decode($response->getBody(), true);
     if ($response->getStatusCode() == 200) {
         if (!is_array($body) && is_string($body)) {
             $body = ['message' => $body];
         }
     } else {
         if (!$body['message']) {
             $body = ['message' => $response->getReasonPhrase(), 'details' => $body];
         }
     }
     return new RuleResponse($code, $body);
 }
開發者ID:rulecom,項目名稱:api-wrapper,代碼行數:15,代碼來源:ResponseFactory.php

示例9: create

 /**
  * @param Response $response
  * @return AuthorizationResponse
  */
 public function create(Response $response)
 {
     if ($response->getStatusCode() === 200) {
         return new AuthorizationResponse($response, AuthorizationResponse::AUTHORISED);
     }
     return new AuthorizationResponse($response, AuthorizationResponse::UNAUTHORISED);
 }
開發者ID:gsdevme,項目名稱:jumpcloud,代碼行數:11,代碼來源:AuthorizationResponseFactory.php

示例10: setLastLogs

 /**
  * Set last logs
  *
  * @param Response|ResponseInterface $response
  */
 public function setLastLogs($response)
 {
     $this->statusCode = $response->getStatusCode();
     $content = json_decode($response->getBody()->getContents());
     $this->message = isset($content->message) ? $content->message : null;
     $this->errors = isset($content->errors) ? $content->errors : null;
 }
開發者ID:plescanicolai,項目名稱:billingSdk,代碼行數:12,代碼來源:Auth.php

示例11: getJsonResponse

 public static function getJsonResponse(GuzzleHttp\Psr7\Response $res)
 {
     if ($res->getStatusCode() == 200) {
         return json_decode($res->getBody()->getContents(), true);
     }
     return [];
 }
開發者ID:jrm2k6,項目名稱:laradit,代碼行數:7,代碼來源:APIRequestHelper.php

示例12: updateGame

 protected function updateGame(\Morpheus\SteamGame $game, \GuzzleHttp\Psr7\Response $response)
 {
     $body = json_decode($response->getBody());
     $result = reset($body);
     if ($response->getStatusCode() == 200 && isset($result->success) && $result->success === true) {
         $game->steam_store_data = json_encode($result->data);
     } elseif ($response->getStatusCode() !== 200) {
         \Log::warning('Steam Store API call failed', ['status code' => $response->getStatusCode(), 'game' => $game]);
     } elseif (!isset($result->success)) {
         \Log::warning('Unexpected Steam Store API response', ['body' => $result, 'game' => $game]);
     } else {
         \Log::notice('Game not found in Steam Store database', ['game' => $game]);
     }
     $game->steam_store_updated = date('Y-m-d H:i:s');
     $game->save();
 }
開發者ID:kamicollo,項目名稱:ProjectMorpheus,代碼行數:16,代碼來源:SteamStoreGames.php

示例13: sendOrchestratorPollRequest

 /**
  * Send poll request from task response
  *
  * If response is not from async task, return null
  *
  * @param Elasticsearch\Job $job
  * @param \GuzzleHttp\Psr7\Response $response
  * @param Encryptor $encryptor
  * @param int $retriesCount
  * @return \GuzzleHttp\Psr7\Response|null
  */
 public function sendOrchestratorPollRequest(Elasticsearch\Job $job, \GuzzleHttp\Psr7\Response $response, Encryptor $encryptor, $retriesCount)
 {
     if ($response->getStatusCode() != 202) {
         return null;
     }
     try {
         $data = ResponseDecoder::decode($response);
         if (!is_array($data)) {
             throw new \Exception('Not json reponse');
         }
         if (empty($data['url'])) {
             return null;
         }
     } catch (\Exception $e) {
         //@TODO log error with debug priority
         return null;
     }
     $timeout = 2;
     try {
         return $this->get($data['url'], array('config' => array('curl' => array(CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_0)), 'headers' => array('X-StorageApi-Token' => $encryptor->decrypt($job->getToken()), 'X-KBC-RunId' => $job->getRunId(), 'X-User-Agent', KeboolaOrchestratorBundle::SYRUP_COMPONENT_NAME . " - JobExecutor", 'X-Orchestrator-Poll', (int) $retriesCount), 'timeout' => 60 * $timeout));
     } catch (RequestException $e) {
         $handlerContext = $e->getHandlerContext();
         if (is_array($handlerContext)) {
             if (array_key_exists('errno', $handlerContext)) {
                 if ($handlerContext['errno'] == CURLE_OPERATION_TIMEOUTED) {
                     $this->logger->debug('curl.debug', array('handlerContext' => $e->getHandlerContext()));
                     throw new Exception\CurlException(sprintf('Task polling timeout after %d minutes', $timeout), $e->getRequest(), $e->getResponse(), $e);
                 }
             }
         }
         throw $e;
     }
 }
開發者ID:keboola,項目名稱:orchestrator-bundle,代碼行數:44,代碼來源:Client.php

示例14: handleError

 /**
  * @throws HttpException
  */
 protected function handleError()
 {
     $body = (string) $this->response->getBody();
     $code = (int) $this->response->getStatusCode();
     $content = json_decode($body);
     throw new HttpException(isset($content->message) ? $content->message : 'Request not processed.', $code);
 }
開發者ID:mix376,項目名稱:DigitalOceanV2,代碼行數:10,代碼來源:GuzzleHttpAdapter.php

示例15: shouldRetry

 /**
  * Indicates if there should be a retry or not.
  * 
  * @param integer                   $retryCount The retry count.
  * @param \GuzzleHttp\Psr7\Response $response   The HTTP response object.
  * 
  * @return boolean
  */
 public function shouldRetry($retryCount, $response)
 {
     if ($retryCount >= $this->_maximumAttempts || array_search($response->getStatusCode(), $this->_retryableStatusCodes) || is_null($response)) {
         return false;
     } else {
         return true;
     }
 }
開發者ID:Azure,項目名稱:azure-storage-php,代碼行數:16,代碼來源:ExponentialRetryPolicy.php


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