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


PHP ResponseInterface::getReasonPhrase方法代碼示例

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


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

示例1: 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

示例2: transformResponseToException

 /**
  * Transform response to an error if possible.
  *
  * @param RequestInterface  $request  Request of the call
  * @param ResponseInterface $response Response of the call
  *
  * @throws ClientErrorException If response status code is a 4xx
  * @throws ServerErrorException If response status code is a 5xx
  *
  * @return ResponseInterface If status code is not in 4xx or 5xx return response
  */
 protected function transformResponseToException(RequestInterface $request, ResponseInterface $response)
 {
     if ($response->getStatusCode() >= 400 && $response->getStatusCode() < 500) {
         throw new ClientErrorException($response->getReasonPhrase(), $request, $response);
     }
     if ($response->getStatusCode() >= 500 && $response->getStatusCode() < 600) {
         throw new ServerErrorException($response->getReasonPhrase(), $request, $response);
     }
     return $response;
 }
開發者ID:xabbuh,項目名稱:plugins,代碼行數:21,代碼來源:ErrorPlugin.php

示例3: validateResponse

 /**
  * Checks if a HTTP response is a valid API response
  * @param  PsrHttpMessageResponseInterface $response The response to check
  * @return PsrHttpMessageResponseInterface           The same response
  * @throws InvalidResponseException
  */
 public static function validateResponse(\Psr\Http\Message\ResponseInterface $response)
 {
     $data = json_decode($response->getBody());
     if ($response->getStatusCode() >= 400 && $response->getStatusCode() < 500) {
         if (false === $data || !is_object($data)) {
             throw new ClientException('Your request returned an error: ' . $response->getStatusCode() . ' ' . $response->getReasonPhrase(), $response->getStatusCode());
         }
     }
     if ($response->getStatusCode() < 200 || $response->getStatusCode() >= 300 && $response->getStatusCode() < 400 || $response->getStatusCode() >= 500) {
         throw new APIException('Unsuccessful API call. Response status: ' . $response->getStatusCode() . ' ' . $response->getReasonPhrase(), $response->getStatusCode(), null, $response);
     }
     if (null === $data && $response->getStatusCode() != 204) {
         $body = $response->getBody();
         $summary = '';
         if ($body->isSeekable()) {
             $size = $body->getSize();
             $summary = $body->read(120);
             $body->rewind();
             if ($size > 120 && strlen($summary) > 120) {
                 $summary .= ' (truncated...)';
             }
             // Matches any printable character, including unicode characters:
             // letters, marks, numbers, punctuation, spacing, and separators.
             if (preg_match('/[^\\pL\\pM\\pN\\pP\\pS\\pZ\\n\\r\\t]/', $summary)) {
                 $summary = '';
             }
         }
         $summary = $summary ? ' Body: ' . $summary : '';
         throw new InvalidResponseException('Response body must be valid JSON.' . $summary, 0, null, $response->getBody());
     }
     if ($data && isset($data->errors) && (is_array($data->errors) || $data->errors instanceof Traversable)) {
         $message = [];
         foreach ($data->errors as $error) {
             $m = $error->title;
             if (isset($error->detail)) {
                 $m .= ' - ' . $error->detail;
             }
             if (isset($error->source) && $error->source instanceof Traversable) {
                 $source = [];
                 foreach ($error->source as $k => $v) {
                     $source[] = $k . ':' . $v;
                 }
                 if ($source) {
                     $m .= ' (' . implode(';', $source) . ')';
                 }
             }
             $message[] = $m;
         }
         $message = 'API responded with code ' . $response->getStatusCode() . ' and the following error(s): ' . implode(', ', $message);
         throw new APIException($message, $response->getStatusCode());
     }
     return $response;
 }
開發者ID:2performant,項目名稱:2performant-php,代碼行數:59,代碼來源:ApiResponse.php

示例4: getResponse

 /**
  * Response about results
  * @param string $contentType
  * @param boolean $assoc
  * @return array
  */
 public function getResponse($contentType = 'json', $assoc = false)
 {
     $response = array('statusCode' => $this->response->getStatusCode(), 'success' => false, 'results' => null, 'message' => $this->response->getReasonPhrase());
     if (in_array($this->response->getStatusCode(), array(200, 201))) {
         $streamBody = $this->response->getBody();
         $bodyString = $streamBody->getContents();
         if ($contentType === 'json') {
             $response['results'] = $this->jsonp_decode($bodyString, $assoc);
         } else {
             $response['results'] = $bodyString;
         }
         $response['success'] = true;
     }
     return $response;
 }
開發者ID:wabel,項目名稱:certain-api-wrapper,代碼行數:21,代碼來源:CertainResponse.php

示例5: 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

示例6: 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

示例7: describe

 /**
  * @param \Psr\Http\Message\RequestInterface $request
  * @param \Psr\Http\Message\ResponseInterface $response
  *
  * @return string
  */
 protected function describe(RequestInterface $request, ResponseInterface $response = null)
 {
     if (!$response) {
         return sprintf('%s %s failed', $request->getMethod(), $request->getUri());
     }
     return sprintf('%s %s returned %s %s', $request->getMethod(), $request->getUri(), $response->getStatusCode(), $response->getReasonPhrase());
 }
開發者ID:hannesvdvreken,項目名稱:guzzle-profiler,代碼行數:13,代碼來源:DescriptionMaker.php

示例8: 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

示例9: sendStatus

 /**
  * Send the status
  *
  * @param   ResponseInterface $response The response object
  *
  * @return  void
  */
 protected function sendStatus(ResponseInterface $response)
 {
     $version = $response->getProtocolVersion();
     $status = $response->getStatusCode();
     $phrase = $response->getReasonPhrase();
     header("HTTP/{$version} {$status} {$phrase}");
 }
開發者ID:nibra,項目名稱:joomla-pythagoras,代碼行數:14,代碼來源:ResponseSenderMiddleware.php

示例10: __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

示例11: checkResponse

 protected function checkResponse(ResponseInterface $response, $data)
 {
     // Metadata info
     $contentTypeRaw = $response->getHeader('Content-Type');
     $contentTypeArray = explode(';', reset($contentTypeRaw));
     $contentType = reset($contentTypeArray);
     // Response info
     $responseCode = $response->getStatusCode();
     $responseMessage = $response->getReasonPhrase();
     // Data info
     $error = !empty($data['error']) ? $data['error'] : null;
     $errorCode = !empty($error['error_code']) ? $error['error_code'] : $responseCode;
     $errorDescription = !empty($data['error_description']) ? $data['error_description'] : null;
     $errorMessage = !empty($error['error_msg']) ? $error['error_msg'] : $errorDescription;
     $message = $errorMessage ?: $responseMessage;
     // Request/meta validation
     if (399 < $responseCode) {
         throw new IdentityProviderException($message, $responseCode, $data);
     }
     // Content validation
     if ('application/json' != $contentType) {
         throw new IdentityProviderException($message, $responseCode, $data);
     }
     if ($error) {
         throw new IdentityProviderException($errorMessage, $errorCode, $data);
     }
 }
開發者ID:j4k,項目名稱:oauth2-vkontakte,代碼行數:27,代碼來源:Vkontakte.php

示例12: httpError

 /**
  * Helper method responsible for constructing and returning {@see BadResponseError} exceptions.
  *
  * @param RequestInterface  $request  The faulty request
  * @param ResponseInterface $response The error-filled response
  *
  * @return BadResponseError
  */
 public function httpError(RequestInterface $request, ResponseInterface $response)
 {
     $message = $this->header('HTTP Error');
     $message .= sprintf("The remote server returned a \"%d %s\" error for the following transaction:\n\n", $response->getStatusCode(), $response->getReasonPhrase());
     $message .= $this->header('Request');
     $message .= trim(str($request)) . PHP_EOL . PHP_EOL;
     $message .= $this->header('Response');
     $message .= trim(str($response)) . PHP_EOL . PHP_EOL;
     $message .= $this->header('Further information');
     // @codeCoverageIgnoreStart
     switch ($response->getStatusCode()) {
         case 400:
             $message .= "Please ensure that your input values are valid and well-formed. ";
             break;
         case 401:
             $message .= "Please ensure that your authentication credentials are valid. ";
             break;
         case 404:
             $message .= "Please ensure that the resource you're trying to access actually exists. ";
             break;
         case 500:
             $message .= "Please try this operation again once you know the remote server is operational. ";
             break;
     }
     // @codeCoverageIgnoreEnd
     $message .= "Visit http://docs.php-opencloud.com/en/latest/http-codes for more information about debugging " . "HTTP status codes, or file a support issue on https://github.com/php-opencloud/openstack/issues.";
     $e = new BadResponseError($message);
     $e->setRequest($request);
     $e->setResponse($response);
     return $e;
 }
開發者ID:alewitt,項目名稱:openstack,代碼行數:39,代碼來源:Builder.php

示例13: __construct

 /**
  * Constructor.
  *
  * @param ResponseInterface $response The API response.
  */
 public function __construct(ResponseInterface $response)
 {
     $apiErrorResponse = new ApiErrorResponse();
     $apiErrorResponse->setStatus($response->getStatusCode());
     $apiErrorResponse->setMessage($response->getReasonPhrase());
     parent::__construct($apiErrorResponse);
 }
開發者ID:speicher210,項目名稱:kontakt.io-api,代碼行數:12,代碼來源:ApiKeyInvalidException.php

示例14: checkResponse

 /**
  * Check a provider response for errors.
  *
  * @throws IdentityProviderException
  * @param  ResponseInterface $response
  * @param  string $data Parsed response data
  * @return void
  */
 protected function checkResponse(ResponseInterface $response, $data)
 {
     $statusCode = $response->getStatusCode();
     if ($statusCode >= 400) {
         throw new IdentityProviderException(isset($data['meta']['errorDetail']) ? $data['meta']['errorDetail'] : $response->getReasonPhrase(), $statusCode, $response);
     }
 }
開發者ID:stevenmaguire,項目名稱:oauth2-foursquare,代碼行數:15,代碼來源:Foursquare.php

示例15: 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


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