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


PHP Response::getStatusCode方法代码示例

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


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

示例1: deduce

 /**
  * @return ErrorResponse|SuccessResponse
  */
 public function deduce()
 {
     /* @var array $response */
     $response = (array) $this->response->json();
     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:mahsanamin,项目名称:box-php-sdk,代码行数:12,代码来源:Response.php

示例2: __construct

 public function __construct(Response $response)
 {
     try {
         $this->details = $response->json();
         $message = $this->details['error']['message'];
     } catch (ParseException $e) {
         $message = $response->getReasonPhrase();
     }
     parent::__construct(sprintf('The request failed and returned an invalid status code ("%d") : %s', $response->getStatusCode(), $message), $response->getStatusCode());
 }
开发者ID:rgazelot,项目名称:Office365Adapter,代码行数:10,代码来源:ApiErrorException.php

示例3: 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:leonardorifeli,项目名称:pagseguro,代码行数:16,代码来源:PagSeguroException.php

示例4: checkResponse

 /**
  * Check the return of a request response
  *
  * @param Response $response 
  * @return false if error, decoded response if valid status
  * @author Niko
  */
 private function checkResponse(Response $response)
 {
     if ($response->getStatusCode() != 200) {
         $res = $response->json();
         var_dump($response->getStatusCode());
         if (isset($res['Error'])) {
             $this->log($response->getStatusCode(), $res['Error']);
         }
         return false;
     }
     return $response->json();
 }
开发者ID:petit2m,项目名称:seriesTracker,代码行数:19,代码来源:GenericService.php

示例5: handleResponse

 protected function handleResponse(Response $response)
 {
     $code = $response->getStatusCode();
     if ($code == 200) {
         return json_decode($response->getBody()->getContents(), true);
     }
     if ($code == 401 && $this->requiresToken) {
         // Unauthorized, invalidate token
         $this->tokenStore->storeToken(null);
     }
     throw new ApiException('Request failed, received the following status: ' . $response->getStatusCode() . ' Body: ' . $response->getBody()->getContents());
 }
开发者ID:atomx,项目名称:atomx-api-php,代码行数:12,代码来源:AtomxClient.php

示例6: handleResponse

 /**
  * @param \GuzzleHttp\Message\Response $response
  * @return Error
  */
 protected function handleResponse($response)
 {
     $contentType = $response->getHeader('content-type');
     if (stripos($contentType, 'application/json') === false) {
         return $response;
     }
     $json = $response->json();
     if ($response->getStatusCode() >= 400) {
         // oops an error with the response
         return new Error($response->getStatusCode(), $json['code'], $json['message']);
     }
     return $json;
 }
开发者ID:nsbucky,项目名称:echosign,代码行数:17,代码来源:Guzzle.php

示例7: handleResponse

 /**
  * @param Response $response
  * @return array|mixed
  * @throws JsonApiResponseException
  */
 public function handleResponse($response)
 {
     $contentType = $response->getHeader('content-type');
     // if its not json, then just return the response and handle it in your own object.
     if (stripos($contentType, 'application/json') === false) {
         return $response;
     }
     $json = $response->json();
     // adobe says hey this didn't work!
     if ($response->getStatusCode() >= 400) {
         // oops an error with the response, from Adobe complaining about something in your code.
         throw new JsonApiResponseException($response->getStatusCode(), $json['message'], $json['code']);
     }
     return $json;
 }
开发者ID:nsbucky,项目名称:echosignv3,代码行数:20,代码来源:GuzzleTransport.php

示例8: formatProvider

 public function formatProvider()
 {
     $request = new Request('PUT', '/', ['x-test' => 'abc'], Stream::factory('foo'));
     $response = new Response(200, ['X-Baz' => 'Bar'], Stream::factory('baz'));
     $err = new RequestException('Test', $request, $response);
     return [['{request}', [$request], (string) $request], ['{response}', [$request, $response], (string) $response], ['{request} {response}', [$request, $response], $request . ' ' . $response], ['{request} {response}', [$request], $request . ' '], ['{req_headers}', [$request], "PUT / HTTP/1.1\r\nx-test: abc"], ['{res_headers}', [$request, $response], "HTTP/1.1 200 OK\r\nX-Baz: Bar"], ['{res_headers}', [$request], 'NULL'], ['{req_body}', [$request], 'foo'], ['{res_body}', [$request, $response], 'baz'], ['{res_body}', [$request], 'NULL'], ['{method}', [$request], $request->getMethod()], ['{url}', [$request], $request->getUrl()], ['{resource}', [$request], $request->getResource()], ['{req_version}', [$request], $request->getProtocolVersion()], ['{res_version}', [$request, $response], $response->getProtocolVersion()], ['{res_version}', [$request], 'NULL'], ['{host}', [$request], $request->getHost()], ['{hostname}', [$request, $response], gethostname()], ['{hostname}{hostname}', [$request, $response], gethostname() . gethostname()], ['{code}', [$request, $response], $response->getStatusCode()], ['{code}', [$request], 'NULL'], ['{phrase}', [$request, $response], $response->getReasonPhrase()], ['{phrase}', [$request], 'NULL'], ['{error}', [$request, $response, $err], 'Test'], ['{error}', [$request], 'NULL'], ['{req_header_x-test}', [$request], 'abc'], ['{req_header_x-not}', [$request], ''], ['{res_header_X-Baz}', [$request, $response], 'Bar'], ['{res_header_x-not}', [$request, $response], ''], ['{res_header_X-Baz}', [$request], 'NULL']];
 }
开发者ID:assad2012,项目名称:EvaOAuth,代码行数:7,代码来源:FormatterTest.php

示例9: handleResponse

 protected function handleResponse(Response $response)
 {
     if ($response->getStatusCode() == 200) {
         return $response->getBody()->getContents();
     }
     throw new ApiException('Request failed, received the following status: ' . $response->getStatusCode() . ' Body: ' . $response->getBody()->getContents());
 }
开发者ID:erikdubbelboer,项目名称:atomx-api-php,代码行数:7,代码来源:ApiClient.php

示例10: status

 /**
  * {@inheritdoc}
  */
 public function status()
 {
     if ($this->response) {
         return $this->response->getStatusCode();
     }
     return false;
 }
开发者ID:stackla,项目名称:stackla-php-sdk,代码行数:10,代码来源:Request.php

示例11: createResponse

 /**
  * Taken from Mink\BrowserKitDriver
  *
  * @param Response $response
  *
  * @return \Symfony\Component\BrowserKit\Response
  */
 protected function createResponse(Response $response)
 {
     $contentType = $response->getHeader('Content-Type');
     $matches = null;
     if (!$contentType or strpos($contentType, 'charset=') === false) {
         $body = $response->getBody(true);
         if (preg_match('/\\<meta[^\\>]+charset *= *["\']?([a-zA-Z\\-0-9]+)/i', $body, $matches)) {
             $contentType .= ';charset=' . $matches[1];
         }
         $response->setHeader('Content-Type', $contentType);
     }
     $headers = $response->getHeaders();
     $status = $response->getStatusCode();
     $matchesMeta = null;
     $matchesHeader = null;
     $isMetaMatch = preg_match('/\\<meta[^\\>]+http-equiv="refresh" content="(\\d*)\\s*;?\\s*url=(.*?)"/i', $response->getBody(true), $matchesMeta);
     $isHeaderMatch = preg_match('~(\\d*);?url=(.*)~', (string) $response->getHeader('Refresh'), $matchesHeader);
     $matches = $isMetaMatch ? $matchesMeta : $matchesHeader;
     if (!empty($matches) && (empty($matches[1]) || $matches[1] < $this->refreshMaxInterval)) {
         $uri = $this->getAbsoluteUri($matches[2]);
         $partsUri = parse_url($uri);
         $partsCur = parse_url($this->getHistory()->current()->getUri());
         foreach ($partsCur as $key => $part) {
             if ($key === 'fragment') {
                 continue;
             }
             if (!isset($partsUri[$key]) || $partsUri[$key] !== $part) {
                 $status = 302;
                 $headers['Location'] = $uri;
                 break;
             }
         }
     }
     return new BrowserKitResponse($response->getBody(), $status, $headers);
 }
开发者ID:itillawarra,项目名称:cmfive,代码行数:42,代码来源:Guzzle.php

示例12: debug

 function debug(\GuzzleHttp\Message\Response $response)
 {
     $this->dump_respuesta = 'status: ' . $response->getStatusCode() . "<br/>body: <br/>" . $response->getBody();
     //un string encodeado utf-8
     $this->dump_url = $response->getEffectiveUrl();
     //un string encodeado utf-8
 }
开发者ID:emma5021,项目名称:toba,代码行数:7,代码来源:ci_cliente_rest.php

示例13: Payment

 function it_maps_declined_response_402_to_payment_result_object(ClientException $exception, Response $response, ResultObjectMapperInterface $resultMapper, MethodInterface $method)
 {
     $result = ['error' => 'Error string'];
     $resultObject = new Payment();
     $response->getStatusCode()->willReturn(402);
     $response->json()->willReturn($result);
     $method->createResultObject()->willReturn($resultObject);
     $exception->getResponse()->willReturn($response);
     $resultMapper->map($result, $resultObject)->shouldBeCalled()->willReturn($resultObject);
     $this->get($exception, $method)->getResult()->shouldReturn($resultObject);
 }
开发者ID:web3d,项目名称:mincart,代码行数:11,代码来源:ExceptionMapperSpec.php

示例14: validateStatusCode

 private function validateStatusCode(\GuzzleHttp\Message\Response $response, Spec\Response $responseSpec, UseCaseValidationReport $report)
 {
     if ($responseSpec->getStatusCode()) {
         $expectedCode = $responseSpec->getStatusCode();
         $actualCode = $response->getStatusCode();
         if ($expectedCode !== $actualCode) {
             $message = sprintf("\t\t<error>Response code should be %s actual value is %s</error>", $expectedCode, $actualCode);
             $this->addViolation($message);
             $report->setStatusCodeViolation($message);
         }
     }
 }
开发者ID:talkrz,项目名称:rest-spec,代码行数:12,代码来源:Response.php

示例15: handleResponse

 /**
  * @param Response $response
  * @return \GuzzleHttp\Stream\StreamInterface|mixed|null|string
  * @throws ApiException
  */
 protected function handleResponse(Response $response)
 {
     if ($response->getStatusCode() == 200) {
         $stream = $response->getBody();
         if ($this->returnStream == true) {
             return $stream;
         } else {
             return parent::handleResponse($response);
         }
     }
     throw new ApiException('Request failed, received the following status: ' . $response->getStatusCode() . ' Body: ' . $response->getBody()->getContents());
 }
开发者ID:atomx,项目名称:atomx-api-php,代码行数:17,代码来源:Report.php


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