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


PHP Response::getStatusCode方法代码示例

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


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

示例1: request

 /**
  * Returns object with properties int:status object:body
  * @param string $method
  * @param string $path
  * @param array $query
  * @param bool $doAuth
  * @throws \InvalidArgumentException
  * @throws \Exception
  * @return \stdClass
  */
 public function request($method, $path, $query = array(), $doAuth = false)
 {
     $this->userAgent = 'Rocker REST Client v' . Server::VERSION;
     $method = strtolower($method);
     $request = $this->initiateRequest($method, $path, $query);
     if ($doAuth) {
         $this->addAuthHeader($request);
     }
     try {
         $this->lastResponse = $request->send();
     } catch (\Guzzle\Http\Exception\ClientErrorResponseException $e) {
         $this->lastResponse = $e->getResponse();
         if ($this->lastResponse->getStatusCode() == 401 && !$doAuth && !empty($this->user)) {
             trigger_error('Doing unauthenticated requests to an URI that requires authentication (' . $path . ')', E_WARNING);
             return $this->request($method, $path, $query, true);
         }
     }
     if ($this->lastResponse->getStatusCode() == 400) {
         throw new ClientException($this->lastResponse, 400);
     }
     if ($this->lastResponse->getStatusCode() == 204) {
         return (object) array('status' => 204, 'body' => array());
     }
     if (strpos($this->lastResponse->getContentType(), 'json') === false) {
         throw new ClientException($this->lastResponse, ClientException::ERR_UNEXPECTED_CONTENT_TYPE, 'Server responded with unexpected content type (' . $this->lastResponse->getContentType() . ')');
     }
     $str = (string) $this->lastResponse->getBody();
     $body = json_decode($str);
     return (object) array('status' => $this->lastResponse->getStatusCode(), 'headers' => $this->headerCollectionToArray($this->lastResponse->getHeaders()), 'body' => $body);
 }
开发者ID:NavalKishor,项目名称:PHP-Rocker,代码行数:40,代码来源:Client.php

示例2: createMessage

 /**
  * @param Response $response
  *
  * @return string
  */
 protected static function createMessage(Response $response)
 {
     if ($response->getStatusCode() != 400) {
         return '[' . $response->getStatusCode() . '] A HTTP error has occurred: ' . $response->getBody(true);
     }
     $message = 'Some errors occurred:';
     foreach ($response->xml()->error as $error) {
         $message .= PHP_EOL . '[' . (string) $error->code . '] ' . (string) $error->message;
     }
     return $message;
 }
开发者ID:amaurymedeiros,项目名称:pagseguro,代码行数:16,代码来源:PagSeguroException.php

示例3: factory

 /**
  * Simple exception factory for creating Intercom standardised exceptions
  *
  * @param RequestInterface $request The Request
  * @param Response $response The response
  * @return BadResponseException
  */
 public static function factory(RequestInterface $request, Response $response)
 {
     $response_json = $response->json();
     $intercom_unavailable_error = NULL;
     if (!static::isValidIntercomError($response_json)) {
         if ($response->isServerError()) {
             $label = 'Server error response';
             $class = __NAMESPACE__ . '\\ServerErrorResponseException';
             $intercom_unavailable_error = 'Service Unavailable: Back-end server is at capacity';
         } else {
             $label = 'Unsuccessful response';
             $class = __CLASS__;
         }
     } elseif ($response->isClientError()) {
         $label = 'Client error response';
         $class = __NAMESPACE__ . '\\ClientErrorResponseException';
     } elseif ($response->isServerError()) {
         $label = 'Server error response';
         $class = __NAMESPACE__ . '\\ServerErrorResponseException';
     } else {
         $label = 'Unsuccessful response';
         $class = __CLASS__;
     }
     $message = $label . PHP_EOL . implode(PHP_EOL, array('[status code] ' . $response->getStatusCode(), '[reason phrase] ' . $response->getReasonPhrase(), '[url] ' . $request->getUrl()));
     $e = new $class($message);
     $e->setResponse($response);
     $e->setRequest($request);
     // Sets the errors if the error response is the standard Intercom error type
     if (static::isValidIntercomError($response_json)) {
         $e->setErrors($response_json['errors']);
     } elseif ($intercom_unavailable_error != NULL) {
         $e->setErrors(array('code' => 'service_unavailable', "message" => $intercom_unavailable_error));
     }
     return $e;
 }
开发者ID:scup,项目名称:intercom-php,代码行数:42,代码来源:IntercomException.php

示例4: handleError

 /**
  * @throws HttpException
  */
 protected function handleError()
 {
     $body = (string) $this->response->getBody(true);
     $code = (int) $this->response->getStatusCode();
     $content = json_decode($body);
     throw new HttpException(isset($content->message) ? $content->message : 'Request not processed.', $code);
 }
开发者ID:skaisser,项目名称:upcloud,代码行数:10,代码来源:GuzzleAdapter.php

示例5: factory

 /**
  * Simple exception factory for creating Intercom standardised exceptions
  *
  * @param RequestInterface $request The Request
  * @param Response $response The response
  * @return BadResponseException
  */
 public static function factory(RequestInterface $request, Response $response)
 {
     if (!static::isValidIntercomError($response->json())) {
         $label = 'Unsuccessful response';
         $class = __CLASS__;
     } elseif ($response->isClientError()) {
         $label = 'Client error response';
         $class = __NAMESPACE__ . '\\ClientErrorResponseException';
     } elseif ($response->isServerError()) {
         $label = 'Server error response';
         $class = __NAMESPACE__ . '\\ServerErrorResponseException';
     } else {
         $label = 'Unsuccessful response';
         $class = __CLASS__;
     }
     $message = $label . PHP_EOL . implode(PHP_EOL, array('[status code] ' . $response->getStatusCode(), '[reason phrase] ' . $response->getReasonPhrase(), '[url] ' . $request->getUrl()));
     $e = new $class($message);
     $e->setResponse($response);
     $e->setRequest($request);
     // Sets the errors if the error response is the standard Intercom error type
     if (static::isValidIntercomError($response->json())) {
         $e->setErrors($response->json()['errors']);
     }
     return $e;
 }
开发者ID:atlir,项目名称:intercom-php,代码行数:32,代码来源:IntercomException.php

示例6: determineCode

 /**
  * Determine an exception code from the given response, exception data and
  * JSON body.
  *
  * @param Response $response
  * @param array    $data
  * @param array    $json
  *
  * @return string|null
  */
 private function determineCode(Response $response, array $data, array $json)
 {
     if (409 === $response->getStatusCode()) {
         return 'DocumentAlreadyExists';
     }
     return $this->determineCodeFromErrors($data['errors']);
 }
开发者ID:sajari,项目名称:sajari-sdk-php,代码行数:17,代码来源:EngineExceptionParser.php

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

示例8: onRequestError

 /**
  * request error
  * @param \Guzzle\Common\Event $event
  */
 public function onRequestError(Event $event)
 {
     $this->request = $event->offsetGet('request');
     $this->response = $event->offsetGet('response');
     $body = $this->response->getBody(true);
     switch ($this->response->getStatusCode()) {
         case 400:
             $this->error400($body);
             break;
         case 520:
             $this->error520($body);
             break;
         default:
             $this->commonError($body);
             break;
     }
 }
开发者ID:cstap,项目名称:kintone-sdk-php,代码行数:21,代码来源:KintoneError.php

示例9: factory

 /**
  * Factory method to create a new Oauth exception.
  *
  * @param RequestInterface $request
  * @param Response $response
  *
  * @return OauthException
  */
 public static function factory(RequestInterface $request, Response $response)
 {
     $message = 'Client error response' . PHP_EOL . implode(PHP_EOL, array('[status code] ' . $response->getStatusCode(), '[reason phrase] ' . $response->getReasonPhrase(), '[url] ' . $request->getUrl()));
     $e = new static($message);
     $e->setResponse($response);
     $e->setRequest($request);
     return $e;
 }
开发者ID:cpliakas,项目名称:magento-client-php,代码行数:16,代码来源:OauthException.php

示例10: isSuccess

 /**
  * Should return if sending the data was successful
  *
  * @return bool
  */
 public function isSuccess()
 {
     $statuscode = $this->response->getStatusCode();
     if (!in_array($statuscode, ['200', '204'])) {
         throw new \Exception('HTTP Code ' . $statuscode . ' ' . $this->response->getBody());
     }
     return true;
 }
开发者ID:undera,项目名称:influxdb-php,代码行数:13,代码来源:Guzzle.php

示例11: fromCommand

 /**
  * {@inheritDoc}
  */
 public static function fromCommand(CommandInterface $command, Response $response)
 {
     $errors = json_decode($response->getBody(true), true);
     $type = array_get($errors, 'error.type', null);
     $code = array_get($errors, 'error.code', null);
     $message = array_get($errors, 'error.message', null);
     $class = '\\Apache\\Usergrid\\Api\\Exception\\' . studly_case($type) . 'Exception';
     if (class_exists($class)) {
         $exception = new $class($message, $response->getStatusCode());
     } else {
         $exception = new static($message, $response->getStatusCode());
     }
     $exception->setErrorType($type);
     $exception->setResponse($response);
     $exception->setRequest($command->getRequest());
     return $exception;
 }
开发者ID:funkyidol,项目名称:usergrid,代码行数:20,代码来源:UsergridException.php

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

示例13: fromCommand

 /**
  * {@inheritDoc}
  */
 public static function fromCommand(CommandInterface $command, Response $response)
 {
     $errors = json_decode($response->getBody(true), true);
     $type = $errors['error']['type'];
     $message = isset($errors['error']['message']) ? $errors['error']['message'] : 'Unknown error';
     $code = isset($errors['error']['code']) ? $errors['error']['code'] : null;
     // We can trigger very specific exception based on the type and code
     if ($type === 'card_error') {
         $exception = new CardErrorException($message, $response->getStatusCode());
     } elseif ($type === 'invalid_request_error' && $code === 'rate_limit') {
         $exception = new ApiRateLimitException($message, $response->getStatusCode());
     } else {
         $exception = new static($message, $response->getStatusCode());
     }
     $exception->setRequest($command->getRequest());
     $exception->setResponse($response);
     return $exception;
 }
开发者ID:netglue,项目名称:zfr-stripe,代码行数:21,代码来源:AbstractResponseException.php

示例14: prepareResponse

 protected function prepareResponse(Response $data)
 {
     if ($data->getStatusCode() != 200) {
         throw new \InvalidArgumentException($data->getReasonPhrase());
     }
     $response = json_decode($data->getBody(), true);
     $this->validateResponse($response);
     return $response;
 }
开发者ID:tripda,项目名称:ring-captcha,代码行数:9,代码来源:RingCaptcha.php

示例15: validate

 /**
  * @param $statusCode
  * @param $url
  * @param RequestInterface $request
  * @param Response $response
  */
 public function validate($statusCode, $url, RequestInterface $request, Response $response)
 {
     if ($response->getStatusCode() === $statusCode) {
         return;
     }
     $message = $url . ' gives a non-200 status code response.';
     $this->logger->warning($message, array('request' => (string) $request, 'response' => (string) $response));
     throw new RuntimeException($message . ' See logs.' . $response->serialize());
 }
开发者ID:janus-ssp,项目名称:client,代码行数:15,代码来源:ResponseStatusCodeValidator.php


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