本文整理汇总了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;
}
示例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;
}