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


PHP ResponseInterface::getStatusCode方法代码示例

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


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

示例1: create

 /**
  * Factory method to create a new exception with a normalized error message
  *
  * @param RequestInterface  $request  Request
  * @param ResponseInterface $response Response received
  * @param \Exception        $previous Previous exception
  * @param array             $ctx      Optional handler context.
  *
  * @return self
  */
 public static function create(RequestInterface $request, ResponseInterface $response = null, \Exception $previous = null, array $ctx = [])
 {
     if (!$response) {
         return new self('Error completing request', $request, null, $previous, $ctx);
     }
     $level = (int) floor($response->getStatusCode() / 100);
     if ($level === 4) {
         $label = 'Client error';
         $className = __NAMESPACE__ . '\\ClientException';
     } elseif ($level === 5) {
         $label = 'Server error';
         $className = __NAMESPACE__ . '\\ServerException';
     } else {
         $label = 'Unsuccessful request';
         $className = __CLASS__;
     }
     $uri = $request->getUri();
     $uri = static::obfuscateUri($uri);
     // Server Error: `GET /` resulted in a `404 Not Found` response:
     // <html> ... (truncated)
     $message = sprintf('%s: `%s` resulted in a `%s` response', $label, $request->getMethod() . ' ' . $uri, $response->getStatusCode() . ' ' . $response->getReasonPhrase());
     $summary = static::getResponseBodySummary($response);
     if ($summary !== null) {
         $message .= ":\n{$summary}\n";
     }
     return new $className($message, $request, $response, $previous, $ctx);
 }
开发者ID:dukt,项目名称:craft-oauth,代码行数:37,代码来源:RequestException.php

示例2: getLastResponseStatus

 /**
  * @return string|null
  */
 public function getLastResponseStatus()
 {
     if (is_null($this->lastResponse)) {
         return null;
     }
     return $this->lastResponse->getStatusCode();
 }
开发者ID:survos,项目名称:platform-api-php,代码行数:10,代码来源:GuzzleListener.php

示例3: checkResponse

 protected function checkResponse(ResponseInterface $response, $data)
 {
     if ($response->getStatusCode() >= 400) {
         $msg = $data['error_description'] ?: (string) $response->getReasonPhrase();
         throw new IdentityProviderException($msg, $response->getStatusCode(), $response);
     }
 }
开发者ID:adam-paterson,项目名称:oauth2-rdio,代码行数:7,代码来源:Rdio.php

示例4: checkResponse

 /**
  * Checks a provider response for errors.
  *
  * @throws IdentityProviderException
  *
  * @param  ResponseInterface $response
  * @param  array|string      $data Parsed response data
  *
  * @return void
  */
 protected function checkResponse(ResponseInterface $response, $data)
 {
     $code = $response->getStatusCode();
     if ($code > 400) {
         throw new IdentityProviderException(isset($data['error']) ? $data['error'] : $response->getReasonPhrase(), $response->getStatusCode(), $response->getBody());
     }
 }
开发者ID:rmartignoni,项目名称:oauth2-strava,代码行数:17,代码来源:Strava.php

示例5: getStatusCode

 /**
  * Get status code of response.
  *
  * @return int
  * @throws ComicApiException
  */
 public function getStatusCode()
 {
     if ($this->response instanceof ResponseInterface) {
         return $this->response->getStatusCode();
     }
     throw new ComicApiException("You can't get response without making request.");
 }
开发者ID:grz-gajda,项目名称:comic-api,代码行数:13,代码来源:GuzzleConnection.php

示例6: checkResponse

 protected function checkResponse(ResponseInterface $response, $data)
 {
     if ($response->getStatusCode() != 200) {
         $data = json_decode($data, true);
         throw new IdentityProviderException($data['message'], $response->getStatusCode(), $data);
     }
 }
开发者ID:gsdevme,项目名称:oauth2-bnet,代码行数:7,代码来源:BattleNet.php

示例7: __invoke

 public function __invoke(ResponseInterface $response)
 {
     $level = $response->getStatusCode() >= 400 ? LogLevel::ERROR : LogLevel::INFO;
     $message = "Request returned " . $response->getStatusCode() . " - " . $response->getReasonPhrase();
     $this->logger->{$level}($message);
     return $response;
 }
开发者ID:downsider,项目名称:log-toolbox,代码行数:7,代码来源:LoggingMiddleware.php

示例8: _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,代码来源:Guzzle6Connection.php

示例9: checkResponse

 /**
  * Check a provider response for errors.
  *
  * @link https://developer.uber.com/v1/api-reference/
  * @throws IdentityProviderException
  * @param  ResponseInterface $response
  * @param  string $data Parsed response data
  * @return void
  */
 protected function checkResponse(ResponseInterface $response, $data)
 {
     $acceptableStatuses = [200, 201];
     if (!in_array($response->getStatusCode(), $acceptableStatuses)) {
         throw new IdentityProviderException($data['message'] ?: $response->getReasonPhrase(), $response->getStatusCode(), $response);
     }
 }
开发者ID:quilam,项目名称:oauth2-ringplus,代码行数:16,代码来源:RingPlus.php

示例10: response

 private function response(ResponseInterface $response)
 {
     if ($response->getStatusCode() !== 200) {
         throw new EventbriteResponseException($response->getStatusCode(), $response->getReasonPhrase());
     }
     return $response->getBody()->getContents();
 }
开发者ID:samhoud,项目名称:eventbrite-plugin,代码行数:7,代码来源:EventbriteAPI.php

示例11: checkResponse

 protected function checkResponse(ResponseInterface $response, $data)
 {
     if ($response->getStatusCode() != 200) {
         $data = is_array($data) ? $data : json_decode($data, true);
         throw new IdentityProviderException($data['error_description'], $response->getStatusCode(), $data);
     }
 }
开发者ID:tpavlek,项目名称:oauth2-bnet,代码行数:7,代码来源:BattleNet.php

示例12: errorCode

 /**
  * Returns the HTTP status code of the error (or false if the HTTP status code is less than 399)
  * @return boolean|int The HTTP status code returned from the API.
  */
 public function errorCode()
 {
     if ($this->isError()) {
         return (int) $this->response->getStatusCode();
     }
     return false;
 }
开发者ID:bobsta63,项目名称:dodns,代码行数:11,代码来源:ApiResponse.php

示例13: processResourceRequestResponse

 /**
  * Checks request response and dispatch result to appropriate handler.
  *
  * @param ResponseInterface $request
  *
  * @return \Exception|mixed
  */
 public function processResourceRequestResponse(ResponseInterface $request)
 {
     $response = json_decode($request->getBody()->getContents());
     if (Response::HTTP_OK !== $request->getStatusCode() && Response::HTTP_CREATED !== $request->getStatusCode()) {
         return ExceptionHandler::handle(get_class($this), $response, $request->getStatusCode());
     }
     return isset($response->data) ? json_decode(json_encode($response->data), true) : json_decode(json_encode($response), true);
 }
开发者ID:MalikAbiola,项目名称:paystack-php-lib,代码行数:15,代码来源:Resource.php

示例14: throwApiExceptionWhenStatusIsUnexpected

 /**
  * @param array $allowedStatusCodes
  * @param ResponseInterface $response
  * @param string $errorMessage
  * @throws \HostedSolr\ApiClient\Exception\HostedSolrApiException
  */
 protected function throwApiExceptionWhenStatusIsUnexpected(array $allowedStatusCodes, $response, $errorMessage)
 {
     if (!in_array($response->getStatusCode(), $allowedStatusCodes)) {
         $exception = new HostedSolrApiException($errorMessage . ' Statuscode: ' . (int) $response->getStatusCode());
         $exception->setResponse($response);
         throw $exception;
     }
 }
开发者ID:timohund,项目名称:hosted_solr-php-api,代码行数:14,代码来源:CoreRestStorageBackend.php

示例15: checkResponse

 /**
  * {@inheritDoc}
  */
 protected function checkResponse(ResponseInterface $response, $data)
 {
     if (isset($data['error'])) {
         if (is_array($data['error'])) {
             throw new IdentityProviderException($data['error']['messageKey'] . ': ' . $data['error']['message'] ?: $response->getReasonPhrase(), $data['error']['code'] ?: $response->getStatusCode(), $response);
         }
         throw new IdentityProviderException($data['error_description'] ?: $response->getReasonPhrase(), $data['error_code'] ?: $response->getStatusCode(), $response);
     }
 }
开发者ID:larabros,项目名称:oauth2-psn,代码行数:12,代码来源:Psn.php


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