当前位置: 首页>>代码示例>>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;未经允许,请勿转载。