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


PHP Response::getStatusCode方法代码示例

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


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

示例1: processResponse

 private function processResponse(Response $response)
 {
     if (null !== $this->logger) {
         $this->logger->info(sprintf('Status Code %s', $response->getStatusCode()));
         $this->logger->debug(var_export($response->getContent(), true));
     }
     if (500 <= $response->getStatusCode()) {
         throw new ApiServerException($response->getStatusCode(), $response->getContent(), $response->getReasonPhrase(), $response->getHeaders());
     }
     if (400 <= $response->getStatusCode()) {
         try {
             $error = $this->parser->parse($response->getContent());
             $error = $error instanceof Model\Error ? $error : new Model\Error();
         } catch (ApiParserException $e) {
             throw new ApiClientException($response->getStatusCode(), $response->getContent(), $response->getReasonPhrase(), $response->getHeaders(), null, $e);
         }
         throw new ApiClientException($response->getStatusCode(), $response->getContent(), $response->getReasonPhrase(), $response->getHeaders(), $error);
     }
     if (204 === $response->getStatusCode()) {
         return true;
     }
     $content = trim($response->getContent());
     if (empty($content)) {
         return true;
     }
     $object = $this->parser->parse($content);
     $object->setApi($this);
     return $object;
 }
开发者ID:iamluc,项目名称:connect,代码行数:29,代码来源:Api.php

示例2: testAddHeadersResetsStatusLine

 public function testAddHeadersResetsStatusLine()
 {
     $response = new Response();
     $this->assertNull($response->getStatusCode());
     $response->addHeaders(array('HTTP/1.0 200 OK'));
     $this->assertEquals(200, $response->getStatusCode());
 }
开发者ID:ChazalFlorian,项目名称:enjoyPangolin,代码行数:7,代码来源:ResponseTest.php

示例3: isValidRequest

 /**
  * Check if request was successfully
  *
  * @param \Buzz\Message\Response $response
  * @return bool
  * @throws \RuntimeException
  */
 protected function isValidRequest(Response $response)
 {
     if ((int) $response->getStatusCode() == 401) {
         throw new \RuntimeException('Invalid Request');
     } elseif ((int) $response->getStatusCode() == 200) {
         return true;
     } elseif ((int) $response->getStatusCode() == 201) {
         return true;
     } elseif ((int) $response->getStatusCode() == 404) {
         throw new \RuntimeException('Page not found!');
     }
     throw new \RuntimeException('Unknown status type:' . $response->getStatusCode());
 }
开发者ID:zeichen32,项目名称:gitlabapi,代码行数:20,代码来源:AbstractApi.php

示例4: factory

 /**
  * @param Request $request
  * @param Response $response
  * 
  * @return HttpException
  */
 public static function factory(Request $request, Response $response)
 {
     if ($response->isClientError()) {
         $label = 'Client error response';
     } elseif ($response->isServerError()) {
         $label = 'Server error response';
     } else {
         $label = 'Unsuccessful response';
     }
     $message = implode(PHP_EOL, array($label, '[status code] ' . $response->getStatusCode(), '[reason phrase] ' . $response->getReasonPhrase(), '[url] ' . $request->getUrl()));
     $e = new static($message, $response->getStatusCode());
     $e->setResponse($response);
     $e->setRequest($request);
     return $e;
 }
开发者ID:Studio-40,项目名称:Payum,代码行数:21,代码来源:HttpException.php

示例5: getResponse

 /**
  * Parse a response.
  *
  * @return \Tev\Bs\Contracts\ResponseInterface
  *
  * @throws \Exception
  * @throws \Tev\Bs\Exception\ErrorResponseException
  */
 public function getResponse()
 {
     $content = json_decode($this->response->getContent());
     if ($content === null) {
         throw new Exception('Failed to get response from server');
     }
     if (isset($content->error) && $content->error) {
         $excp = new ErrorResponseException($content->message, $this->response->getStatusCode());
         $excp->setResponse(new Response($content, $this->endpoint));
         throw $excp;
     }
     if (isset($content->per_page)) {
         return new PaginatedResponse($content, $this->endpoint);
     }
     return new Response($content, $this->endpoint);
 }
开发者ID:tinavas,项目名称:booking-api,代码行数:24,代码来源:Parser.php

示例6: verifyResult

 /**
  * Verifies the last request.
  * If the last request was not successful, it will be throw an exception.
  *
  * @param \Buzz\Message\Response $response The response object from the last reques
  * @param string $url The url which was requested
  * @return \Buzz\Message\Response
  * @throws \Exception
  */
 protected function verifyResult(\Buzz\Message\Response $response, $url)
 {
     if ($response->getStatusCode() !== 200) {
         throw new \Exception('Request to "' . $url . '" failed', 1364061673);
     }
     return $response;
 }
开发者ID:sschuberth,项目名称:Gerrie,代码行数:16,代码来源:HTTPDataService.php

示例7: parse

 /**
  * @param Response $curlResponse
  *
  * @throws HttpStatusParserException
  */
 public function parse(Response $curlResponse)
 {
     $statusCode = $curlResponse->getStatusCode();
     if ($this->shouldThrowException($statusCode)) {
         throw new HttpStatusParserException($curlResponse->getContent(), $statusCode);
     }
 }
开发者ID:krzysztof-gzocha,项目名称:payu,代码行数:12,代码来源:HttpStatusParser.php

示例8: bind

 /**
  * @param Buzz\Message\Response                        $response
  * @param AntiMattr\Twitter\Marketplace\Model\Merchant $merchant
  *
  * @throws AntiMattr\Twitter\Marketplace\Exception\Http\BadRequestException
  * @throws AntiMattr\Twitter\Marketplace\Exception\Http\InternalErrorException
  * @throws AntiMattr\Twitter\Marketplace\Exception\Http\NotFoundException
  * @throws AntiMattr\Twitter\Marketplace\Exception\Http\UnauthorizedException
  */
 public function bind(Response $response, $merchant)
 {
     $status = $response->getStatusCode();
     if (400 == $status) {
         throw new BadRequestException();
     }
     if (401 == $status) {
         throw new UnauthorizedException();
     }
     if (404 == $status) {
         throw new NotFoundException();
     }
     if (500 == $status) {
         throw new InternalErrorException();
     }
     $content = $this->getContent($response);
     if (isset($content->support) && isset($content->support->email)) {
         $merchant->setSupportEmail($content->support->email);
     }
     if (isset($content->name)) {
         $merchant->setName($content->name);
     }
     if (isset($content->email)) {
         $merchant->setEmail($content->email);
     }
     if (isset($content->state)) {
         $merchant->setState(strtoupper($content->state));
     }
     if (isset($content->domains) && is_array($content->domains)) {
         $collection = new ArrayCollection($content->domains);
         $merchant->setDomains($collection);
     }
     if (isset($content->id)) {
         $merchant->setId($content->id);
     }
     if (isset($content->external_id)) {
         $merchant->setExternalId($content->external_id);
     }
     if (isset($content->address)) {
         $data = $content->address;
         $address = $merchant->getAddress();
         if (isset($data->city)) {
             $address->setLocality($data->city);
         }
         if (isset($data->state)) {
             $address->setRegion($data->state);
         }
         if (isset($data->street1)) {
             $address->setStreetAddressLine1($data->street1);
         }
         if (isset($data->country)) {
             $address->setCountry($data->country);
         }
         if (isset($data->postal_code)) {
             $address->setPostalCode($data->postal_code);
         }
     }
 }
开发者ID:antimattr,项目名称:twitter-marketplace,代码行数:67,代码来源:MerchantResponseHandler.php

示例9: __construct

 /**
  * @param string|null $message
  */
 public function __construct(RequestInterface $request, Response $response, $message = null)
 {
     $this->request = $request;
     $this->response = $response;
     if ($message === null) {
         $curlError = $response->getHeader('X-Curl-Error-Result');
         $message = sprintf('HTTP %s request to "%s%s" failed: %d - "%s".', $request->getMethod(), $request->getHost(), $request->getResource(), $curlError ?: $response->getStatusCode(), $curlError ? curl_strerror($curlError) : $response->getReasonPhrase());
     }
     parent::__construct($message);
 }
开发者ID:vaniocz,项目名称:VanioBuzzBundle,代码行数:13,代码来源:RequestFailedException.php

示例10: createFromResponse

 /**
  * @param Response $response
  * @return ProxyMediaInterface
  *
  * @throws MediaStorageClientManagerNotFoundException
  * @throws MediaStorageClientProxyMediaManagerException
  */
 public function createFromResponse(Response $response)
 {
     if ($response && $response->isOk()) {
         $content = json_decode($response->getContent(), true);
         if ($content && !json_last_error() && is_array($content)) {
             $content = new ArrayCollection($content);
         } else {
             throw new MediaStorageClientProxyMediaManagerException('Client not response new value');
         }
     } elseif ($response->getStatusCode() == 404) {
         throw new MediaStorageClientManagerNotFoundException(sprintf('Unable to find the object'));
     } else {
         throw new MediaStorageClientProxyMediaManagerException('Client response code: ' . $response->getStatusCode());
     }
     $proxyMedia = $this->create();
     $proxyMedia->setReferenceFull($content->get('reference_full'));
     $proxyMedia->setName($content->get('name'));
     $proxyMedia->setProviderMetadata($content->toArray());
     return $proxyMedia;
 }
开发者ID:avtonom,项目名称:media-storage-client-bundle,代码行数:27,代码来源:ProxyMediaManager.php

示例11: assertHttpResponseCodeEquals

 protected function assertHttpResponseCodeEquals(HttpResponse $response, $expected)
 {
     $responseCode = $response->getStatusCode();
     if ($responseCode != $expected) {
         $errorMessageString = '';
         if (strpos($response->getHeader('Content-Type'), 'application/vnd.ez.api.ErrorMessage+xml') !== false) {
             $body = \simplexml_load_string($response->getContent());
             $errorMessageString = $this->getHttpResponseCodeErrorMessage($body);
         } elseif (strpos($response->getHeader('Content-Type'), 'application/vnd.ez.api.ErrorMessage+json') !== false) {
             $body = json_decode($response->getContent());
             $errorMessageString = $this->getHttpResponseCodeErrorMessage($body->ErrorMessage);
         }
         self::assertEquals($expected, $responseCode, $errorMessageString);
     }
 }
开发者ID:emodric,项目名称:ezpublish-kernel,代码行数:15,代码来源:TestCase.php

示例12: convertResponse

 /**
  * Converts a buzz response to a pinterest response.
  *
  * @param Request      $request      The request.
  * @param BuzzResponse $buzzResponse The buzz response.
  *
  * @return Response The response.
  */
 private static function convertResponse(Request $request, BuzzResponse $buzzResponse)
 {
     $statusCode = $buzzResponse->getStatusCode();
     $rawBody = (string) $buzzResponse->getContent();
     $rawHeaders = $buzzResponse->getHeaders();
     $headers = array();
     foreach ($rawHeaders as $header) {
         if (stristr($header, 'HTTP/1.')) {
             continue;
         }
         list($key, $value) = explode(': ', $header);
         $headers[$key] = $value;
     }
     return new Response($request, $statusCode, $rawBody, $headers);
 }
开发者ID:hansott,项目名称:pinterest-php,代码行数:23,代码来源:BuzzClient.php

示例13: assertHttpResponseCodeEquals

 protected function assertHttpResponseCodeEquals(HttpResponse $response, $expected)
 {
     $responseCode = $response->getStatusCode();
     if ($responseCode != $expected) {
         $errorMessageString = '';
         if ($response->getHeader('Content-Type') == 'application/vnd.ez.api.ErrorMessage+xml') {
             $body = \simplexml_load_string($response->getContent());
             $errorMessageString = $body->errorDescription;
         } elseif ($response->getHeader('Content-Type') == 'application/vnd.ez.api.ErrorMessage+json') {
             $body = json_decode($response->getContent());
             $errorMessageString = "Error message: {$body->ErrorMessage->errorDescription}";
         }
         self::assertEquals($expected, $responseCode, $errorMessageString);
     }
 }
开发者ID:Heyfara,项目名称:ezpublish-kernel,代码行数:15,代码来源:TestCase.php

示例14: bind

 /**
  * @param Buzz\Message\Response                     $response
  * @param AntiMattr\Twitter\Marketplace\Model\Order $order
  *
  * @throws AntiMattr\Twitter\Marketplace\Exception\Http\BadRequestException
  * @throws AntiMattr\Twitter\Marketplace\Exception\Http\InternalErrorException
  * @throws AntiMattr\Twitter\Marketplace\Exception\Http\NotFoundException
  * @throws AntiMattr\Twitter\Marketplace\Exception\Http\UnauthorizedException
  */
 public function bind(Response $response, $order)
 {
     $status = $response->getStatusCode();
     if (400 == $status) {
         throw new BadRequestException();
     }
     if (401 == $status) {
         throw new UnauthorizedException();
     }
     if (404 == $status) {
         throw new NotFoundException();
     }
     if (500 == $status) {
         throw new InternalErrorException();
     }
 }
开发者ID:antimattr,项目名称:twitter-marketplace,代码行数:25,代码来源:OrderResponseHandler.php

示例15: handleResponse

 /**
  * @param Response $response
  * @return mixed
  * @throws BadAuthentificationException
  */
 public function handleResponse(Response $response)
 {
     $data = json_decode($response->getContent(), true);
     if ($response->getStatusCode() != 200) {
         if (!$data) {
             $e = new BadAuthentificationException("Authentification request has failed : {$response}");
             $e->setOAuthErrorName("undefined");
             $e->setOAuthErrorDescription("Can't handle API response.");
             throw $e;
         }
         $e = new BadAuthentificationException(sprintf("OAuth exception. %s : %s", $data['error'], $data['error_description']));
         $e->setOAuthErrorName($data['error']);
         $e->setOAuthErrorDescription($data['error_description']);
         throw $e;
     }
     return $data;
 }
开发者ID:NathanVss,项目名称:oauth-extension-bundle,代码行数:22,代码来源:EmailTokenProvider.php


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