當前位置: 首頁>>代碼示例>>PHP>>正文


PHP false::getBody方法代碼示例

本文整理匯總了PHP中false::getBody方法的典型用法代碼示例。如果您正苦於以下問題:PHP false::getBody方法的具體用法?PHP false::getBody怎麽用?PHP false::getBody使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在false的用法示例。


在下文中一共展示了false::getBody方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: getResponseArray

 /**
  * Transfoms the response body (json) into an array we can more easily
  * work with.
  *
  * @param \GuzzleHttp\Message\Response|false $response
  *
  * @return array
  */
 public function getResponseArray($response)
 {
     $return = [];
     if (!$response instanceof \GuzzleHttp\Message\Response) {
         $this->errors[] = ['source' => 'client', 'attribute' => null, 'kind' => 'networking', 'message' => 'no response'];
         return $return;
     }
     /**
      * add error for bad status codes
      */
     $code = $response->getStatusCode();
     $errorCodes = [404, 401, 500];
     if (in_array($code, $errorCodes)) {
         $this->errors[] = ['source' => 'client', 'attribute' => null, 'kind' => 'status_code', 'message' => 'Bad status code: ' . $code];
     }
     $body = $response->getBody();
     $body = trim((string) $body);
     /**
      * Return early if we have an empty body, which we can't turn into an array
      * anyway. This happens in cases where the API returns a 404, and possibly
      * other status codes.
      */
     if (empty($body)) {
         return $return;
     }
     $return = json_decode($body, true);
     // set errors, if any
     if (!empty($return['result']['errors'])) {
         foreach ($return['result']['errors'] as $error) {
             $this->errors[] = $error;
         }
     }
     /**
      * NOTE: There is also, maybe, an errors array nested in $return['meta']['errors']
      *       Why is this API so inconsistent???!!!!!
      */
     return $return;
 }
開發者ID:JLMorales,項目名稱:chargify-sdk-php,代碼行數:46,代碼來源:AbstractEntity.php

示例2: getResponseArray

 /**
  * Transfoms the response body (json) into an array we can more easily
  * work with.
  *
  * @param \GuzzleHttp\Message\Response|false $response
  *
  * @return array
  * @todo $this->_errors is populated with errors from Chargify. Should this also populate a separate errors array when we get HTTP 404s or 201s?
  */
 public function getResponseArray($response)
 {
     $return = array();
     if (!$response instanceof \GuzzleHttp\Psr7\Response) {
         $this->_errors['Crucial_Service_Chargify']['networking error'] = 'no response';
         return $return;
     }
     $body = $response->getBody();
     $body = trim((string) $body);
     /**
      * return early on bad status codes
      */
     $code = $response->getStatusCode();
     $errorCodes = array(404, 401, 500);
     if (in_array($code, $errorCodes)) {
         $this->_errors['Crucial_Service_Chargify']['Bad status code'] = $code;
         return $return;
     }
     /**
      * Return early if we have an empty body, which we can't turn into an array
      * anyway. This happens in cases where the API returns a 404, and possibly
      * other status codes.
      */
     if (empty($body)) {
         return $return;
     }
     $return = json_decode($body, true);
     // set errors, if any
     if (!empty($return['errors'])) {
         $this->_errors = $return['errors'];
     }
     return $return;
 }
開發者ID:andrewlamers,項目名稱:chargify-sdk-php,代碼行數:42,代碼來源:AbstractEntity.php


注:本文中的false::getBody方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。