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


PHP Response::isSuccess方法代码示例

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


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

示例1: checkResponseStatus

 /**
  * Check response status
  *
  * @throws ApigilityClient\Exception\RuntimeException
  * @return Bool
  */
 private function checkResponseStatus()
 {
     if (!$this->httpResponse->isSuccess()) {
         return new TriggerException($this->httpClient, $this->httpResponse);
     }
     return true;
 }
开发者ID:ma-si,项目名称:apigility-client,代码行数:13,代码来源:Response.php

示例2: setFromResponseObj

 /**
  * @param HttpResponse $response
  *
  * @return $this
  */
 public function setFromResponseObj(HttpResponse $response)
 {
     if ($response->isSuccess()) {
         $this->setStatus($response->isSuccess());
     } else {
         $this->setError($response->getReasonPhrase());
     }
     return $this;
 }
开发者ID:szmnmichalowski,项目名称:zf2-nocaptcha,代码行数:14,代码来源:Response.php

示例3: dispatchRequestAndDecodeResponse

 protected function dispatchRequestAndDecodeResponse($url, $method, $data = null)
 {
     $request = new Request();
     $this->lastResponse = null;
     $request->getHeaders()->addHeaders(array('Content-Type' => 'application/x-www-form-urlencoded; charset=UTF-8', 'Accept' => 'application/json', 'User-Agent' => 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:37.0) Gecko/20100101 Firefox/37.0'));
     if (!empty($this->host)) {
         $request->getHeaders()->addHeaders(array('Host' => $this->host));
     }
     if (!empty($this->key)) {
         $request->getHeaders()->addHeaders(array('Authorization' => 'Bearer ' . $this->key));
     }
     $request->setUri($url);
     $request->setMethod($method);
     if (is_null($data)) {
         $data = array();
     }
     if (isset($this->key)) {
         $data["auth"] = $this->key;
     }
     if ($method == "POST" || $method == "PUT") {
         $request->setPost(new Parameters($data));
         if (isset($this->key)) {
             $request->setQuery(new Parameters(array('auth' => $this->key)));
         }
     } else {
         $request->setQuery(new Parameters($data));
     }
     $this->lastResponse = $this->httpClient->send($request);
     if ($this->lastResponse->isSuccess()) {
         return json_decode($this->lastResponse->getBody(), true);
     } else {
         return array('error' => true, 'headers' => array("code" => $this->lastResponse->getStatusCode(), "reasons" => $this->lastResponse->getReasonPhrase()), 'body' => json_decode($this->lastResponse->getBody(), true));
     }
 }
开发者ID:dsi-agpt,项目名称:minibus,代码行数:34,代码来源:Client.php

示例4: handleResponse

 /**
  * {@inheritdoc}
  * @see \InoOicClient\Oic\AbstractResponseHandler::handleResponse()
  */
 public function handleResponse(\Zend\Http\Response $httpResponse)
 {
     $responseData = null;
     $decodeException = null;
     try {
         $responseData = $this->getJsonCoder()->decode($httpResponse->getBody());
     } catch (\Exception $e) {
         $decodeException = $e;
     }
     if (!$httpResponse->isSuccess()) {
         if (isset($responseData[Param::ERROR])) {
             $error = $this->getErrorFactory()->createErrorFromArray($responseData);
             $this->setError($error);
             return;
         } else {
             throw new HttpErrorStatusException(sprintf("Error code '%d' from server", $httpResponse->getStatusCode()));
         }
     }
     if (null !== $decodeException) {
         throw new InvalidResponseFormatException('The HTTP response does not contain valid JSON', null, $decodeException);
     }
     try {
         $this->response = $this->getResponseFactory()->createResponse($responseData);
     } catch (\Exception $e) {
         throw new Exception\InvalidResponseException(sprintf("Invalid response: [%s] %s", get_class($e), $e->getMessage()), null, $e);
     }
 }
开发者ID:publicitas-deployment,项目名称:php-openid-connect-client,代码行数:31,代码来源:ResponseHandler.php

示例5: __construct

 /**
  * Construtor.
  *
  * @param Zend\Http\Client   $client
  * @param Zend\Http\Response $response
  */
 public function __construct(ZendHttpClient $client, ZendHttpResponse $response, $depth = 0)
 {
     $this->httpClient = $client;
     $this->httpResponse = $response;
     if (!$this->httpResponse->isSuccess()) {
         $error = json_decode($this->httpResponse->getBody());
         if (empty($error)) {
             $error = new \stdClass();
             $error->status = $this->httpResponse->getStatusCode();
             $error->title = $this->httpResponse->getReasonPhrase();
             $error->detail = '';
         }
         if (!isset($error->status)) {
             $error->status = 500;
         }
         if (!isset($error->detail)) {
             $error->detail = 'An error occurred.';
         }
         throw new RuntimeException(json_encode($error, null, 100), $error->status);
     }
     if (!$this->httpResponse->getHeaders()->has('Content-Type')) {
         throw new RuntimeException("Missing 'Content-Type' header.", 500);
     }
     $contentType = $this->httpResponse->getHeaders()->get('Content-Type')->getFieldValue();
     $pos = strpos($contentType, ';');
     if ($pos !== false) {
         $contentType = substr($contentType, 0, $pos);
     }
     if (empty($this->httpResponse->getBody())) {
         $this->content = null;
     } elseif ($contentType == 'application/hal+json' || $contentType == 'application/json') {
         $this->content = new Resource(Hal::fromJson($this->httpResponse->getBody(), $depth));
     } elseif ($contentType == 'application/hal+xml' || $contentType == 'application/xml') {
         $this->content = new Resource(Hal::fromXml($this->httpResponse->getBody(), $depth));
     } else {
         throw new RuntimeException("Unable to handle content type '{$contentType}' for response: '{$this->httpResponse->getBody()}'.", 500);
     }
 }
开发者ID:mt-olympus,项目名称:hermes,代码行数:44,代码来源:Response.php

示例6: checkForHttpError

 /**
  * Check for HTTP errors in a response.
  *
  * @param \Zend\Http\Response $result The response to check.
  *
  * @throws BackendException
  * @return void
  */
 public function checkForHttpError($result)
 {
     if (!$result->isSuccess()) {
         throw HttpErrorException::createFromResponse($result);
     }
 }
开发者ID:grharry,项目名称:vufind,代码行数:14,代码来源:Connector.php

示例7: parseResponse

 /**
  * @param  HttpResponse $response
  * @throws Exception\RuntimeException if an error occurred on Postage side
  * @return array
  */
 private function parseResponse(HttpResponse $response)
 {
     $result = json_decode($response->getBody(), true);
     if ($response->isSuccess()) {
         return isset($result['data']) ? $result['data'] : array();
     }
     if ($result['response']['status'] !== 'ok') {
         $errors = false;
         if (isset($result['data']) && isset($result['data']['errors'])) {
             $errors = implode(', ', $result['data']['errors']);
         }
         if (isset($result['response']['message'])) {
             throw new Exception\RuntimeException(sprintf('An error occurred on Postage, message: %s%s', $result['response']['message'], $errors ? ' (' . $errors . ')' : ''));
         } else {
             throw new Exception\RuntimeException(sprintf('An error occurred on Postage, status code: %s%s', $result['response']['status'], $errors ? ' (' . $errors . ')' : ''), (int) $result['response']['status']);
         }
     }
     // We need to return an array and not throw an exception because of the poor Postage API
     // error handling, it may returns an empty array with just status === 'ok'
     return array();
 }
开发者ID:erik-maas,项目名称:SlmMail,代码行数:26,代码来源:PostageService.php

示例8: parseResponse

 /**
  * @param  HttpResponse $response
  * @throws Exception\InvalidCredentialsException
  * @throws Exception\ValidationErrorException
  * @throws Exception\RuntimeException
  * @return array
  */
 private function parseResponse(HttpResponse $response)
 {
     $result = json_decode($response->getBody(), true);
     if ($response->isSuccess()) {
         return $result;
     }
     switch ($response->getStatusCode()) {
         case 401:
             throw new Exception\InvalidCredentialsException('Authentication error: missing or incorrect Postmark API Key header');
         case 422:
             throw new Exception\ValidationErrorException(sprintf('An error occured on Postmark (error code %s), message: %s', $result['ErrorCode'], $result['Message']), (int) $result['ErrorCode']);
         case 500:
             throw new Exception\RuntimeException('Postmark server error, please try again');
         default:
             throw new Exception\RuntimeException('Unknown error during request to Postmark server');
     }
 }
开发者ID:erik-maas,项目名称:SlmMail,代码行数:24,代码来源:PostmarkService.php

示例9: parseResponse

 /**
  * @param  HttpResponse $response
  * @throws Exception\InvalidCredentialsException
  * @throws Exception\ValidationErrorException
  * @throws Exception\UnknownTemplateException
  * @throws Exception\RuntimeException
  * @return array
  */
 private function parseResponse(HttpResponse $response)
 {
     $result = json_decode($response->getBody(), true);
     if ($response->isSuccess()) {
         return $result;
     }
     switch ($result['name']) {
         case 'InvalidKey':
             throw new Exception\InvalidCredentialsException(sprintf('Mandrill authentication error (code %s): %s', $result['code'], $result['message']));
         case 'ValidationError':
             throw new Exception\ValidationErrorException(sprintf('An error occurred on Mandrill (code %s): %s', $result['code'], $result['message']));
         case 'Unknown_Template':
             throw new Exception\UnknownTemplateException(sprintf('An error occurred on Mandrill (code %s): %s', $result['code'], $result['message']));
         default:
             throw new Exception\RuntimeException(sprintf('An error occurred on Mandrill (code %s): %s', $result['code'], $result['message']));
     }
 }
开发者ID:roelvanduijnhoven,项目名称:SlmMail,代码行数:25,代码来源:MandrillService.php

示例10: parseResponse

 /**
  * @param  HttpResponse $response
  * @throws Exception\RuntimeException
  * @return array
  */
 private function parseResponse(HttpResponse $response)
 {
     $result = json_decode($response->getBody(), true);
     if ($response->isSuccess()) {
         return $result;
     }
     // There is a 4xx error
     if ($response->isClientError()) {
         if (isset($result['errors']) && is_array($result['errors'])) {
             $message = implode(', ', $result['errors']);
         } elseif (isset($result['error'])) {
             $message = $result['error'];
         } else {
             $message = 'Unknown error';
         }
         throw new Exception\RuntimeException(sprintf('An error occured on SendGrid (http code %s), message: %s', $response->getStatusCode(), $message));
     }
     // There is a 5xx error
     throw new Exception\RuntimeException('SendGrid server error, please try again');
 }
开发者ID:erik-maas,项目名称:SlmMail,代码行数:25,代码来源:SendGridService.php

示例11: checkForHttpError

 /**
  * Check for HTTP errors in a response.
  *
  * @param \Zend\Http\Response $result The response to check.
  *
  * @throws \Exception
  * @return void
  */
 public function checkForHttpError($result)
 {
     if (!$result->isSuccess()) {
         throw new \Exception('HTTP error ' . $result->getStatusCode());
     }
 }
开发者ID:no-reply,项目名称:cbpl-vufind,代码行数:14,代码来源:SRU.php

示例12: isError

 /**
  * Did an error occur in the request?
  *
  * @return bool
  */
 public function isError()
 {
     return !$this->httpResponse->isSuccess();
 }
开发者ID:emus,项目名称:php-zend2-old,代码行数:9,代码来源:Response.php

示例13: isHttpStatusSuccessful

 /**
  * Returns true if the Http status code is 200 or 201 or 204; false otherwise
  *
  * @return bool
  */
 public function isHttpStatusSuccessful()
 {
     return $this->serverRawResponse->isSuccess();
 }
开发者ID:mslib,项目名称:remote-host,代码行数:9,代码来源:AbstractResponseWrapper.php

示例14: parseResponse

 /**
  * @param  HttpResponse $response
  * @throws Exception\InvalidCredentialsException
  * @throws Exception\ValidationErrorException
  * @throws Exception\RuntimeException
  * @return array
  */
 private function parseResponse(HttpResponse $response)
 {
     $result = json_decode($response->getBody(), true);
     if ($response->isSuccess()) {
         return $result;
     }
     switch ($response->getStatusCode()) {
         case 400:
             throw new Exception\ValidationErrorException(sprintf('An error occured on Mailgun, reason: %s', $response->getReasonPhrase()));
         case 401:
             throw new Exception\InvalidCredentialsException('Authentication error: missing or incorrect Mailgun authorization');
         case 402:
             throw new Exception\RuntimeException(sprintf('An error occured on Mailgun, reason: %s', $response->getReasonPhrase()));
         case 500:
         case 502:
         case 503:
         case 504:
             throw new Exception\RuntimeException('Mailgun server error, please try again');
         default:
             throw new Exception\RuntimeException('Unknown error during request to Mailgun server');
     }
 }
开发者ID:erik-maas,项目名称:SlmMail,代码行数:29,代码来源:MailgunService.php

示例15: processResponse

 protected function processResponse(Response $response)
 {
     if (!$response->isSuccess()) {
         $data = json_decode($response->getBody(), self::JSON_DECODE_TYPE_ARRAY, self::JSON_DECODE_DEPTH);
         if (is_array($data) && array_key_exists('status', $data) && is_array($data['status']) && array_key_exists('code', $data['status']) && array_key_exists('message', $data['status'])) {
             throw new RuntimeException($data['status']['message'], $data['status']['code'], new RuntimeException($response, -1, new RuntimeException($this->getClient()->getLastRawRequest())));
         }
         throw new RuntimeException($response->getReasonPhrase(), $response->getStatusCode(), new RuntimeException($response, -1, new RuntimeException($this->getClient()->getLastRawRequest())));
     }
     $data = json_decode($response->getBody(), self::JSON_DECODE_TYPE_ARRAY, self::JSON_DECODE_DEPTH);
     if (!is_array($data)) {
         throw new RuntimeException($response->getReasonPhrase(), $response->getStatusCode(), new RuntimeException($response, -1, new RuntimeException($this->getClient()->getLastRawRequest())));
     }
     if (is_array($data) && array_key_exists('status', $data) && is_array($data['status']) && array_key_exists('code', $data['status']) && array_key_exists('message', $data['status']) && $data['status']['code'] < 0) {
         throw new RuntimeException($data['status']['message'], $data['status']['code'], new RuntimeException($response, -1, new RuntimeException($this->getClient()->getLastRawRequest())));
     }
     return $data;
 }
开发者ID:necromant2005,项目名称:bigml-php-sdk,代码行数:18,代码来源:BigMl.php


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