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


PHP false::getStatusCode方法代码示例

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


在下文中一共展示了false::getStatusCode方法的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::getStatusCode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。