本文整理汇总了PHP中ActivitiResponseObject::fromArray方法的典型用法代码示例。如果您正苦于以下问题:PHP ActivitiResponseObject::fromArray方法的具体用法?PHP ActivitiResponseObject::fromArray怎么用?PHP ActivitiResponseObject::fromArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ActivitiResponseObject
的用法示例。
在下文中一共展示了ActivitiResponseObject::fromArray方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parseResponse
public function parseResponse($url, $response, $returnType, $isArray, $expectedHttpCodes, $errorHttpCodes)
{
// parse response
$header = false;
$content = array();
$status = null;
foreach (explode("\r\n", $response) as $line) {
if (strpos($line, 'HTTP/1.1') === 0) {
$lineParts = explode(' ', $line);
$status = intval($lineParts[1]);
$header = true;
} else {
if ($line == '') {
$header = false;
} else {
if ($header) {
$line = explode(': ', $line);
switch ($line[0]) {
case 'Status':
$status = intval(substr($line[1], 0, 3));
break;
}
} else {
$content[] = $line;
}
}
}
}
if (is_null($status)) {
throw new ActivitiClientException("No valid response accepted, URL [{$url}]", ActivitiClientException::NO_VALID_RESPONSE);
}
if (in_array($status, $expectedHttpCodes)) {
$response = implode("\r\n", $content);
if (!trim($response)) {
return;
}
if ($returnType == 'string') {
return $response;
}
$response = json_decode($response);
if ($returnType) {
if ($isArray) {
return ActivitiResponseObject::fromArray($response, $returnType);
}
return new $returnType($response);
}
return;
}
if ($response && json_decode(implode("\n", $content))) {
$error = json_decode(implode("\n", $content));
if (isset($error->statusCode) && isset($error->errorMessage)) {
throw new ActivitiClientException("Status [{$error->statusCode}], URL [{$url}]: {$error->errorMessage}", ActivitiClientException::INVALID_HTTP_CODE);
}
}
if (isset($errorHttpCodes[$status])) {
throw new ActivitiClientException("Status [{$status}], URL [{$url}]: " . $errorHttpCodes[$status], ActivitiClientException::INVALID_HTTP_CODE);
}
if (ActivitiResponseType::isExpectedCode($status)) {
throw new ActivitiClientException("Status [{$status}], URL [{$url}]: " . ActivitiResponseType::getCodeDescription($status), ActivitiClientException::INVALID_HTTP_CODE);
}
throw new ActivitiClientException("Unexpected status [{$status}], URL [{$url}]", ActivitiClientException::INVALID_HTTP_CODE);
}