本文整理汇总了PHP中HttpResponse::setVersion方法的典型用法代码示例。如果您正苦于以下问题:PHP HttpResponse::setVersion方法的具体用法?PHP HttpResponse::setVersion怎么用?PHP HttpResponse::setVersion使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpResponse
的用法示例。
在下文中一共展示了HttpResponse::setVersion方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parseResponse
/**
* Parses the raw HTTP response and returns a response object
**/
protected function parseResponse($output, $ch = null)
{
$response = new HttpResponse();
if ($output) {
$lines = explode("\n", $output);
$isHeader = true;
$buffer = array();
foreach ($lines as $line) {
if ($isHeader) {
if (preg_match('/^\\s*$/', $line)) {
// Header/body separator
$isHeader = false;
} else {
// This is a real HTTP header
if (preg_match('/^([^:]+)\\:(.*)$/', $line, $matches)) {
//echo "HEADER: [", $matches[1], ']: [', $matches[2], "]\n";
$name = trim($matches[1]);
$value = trim($matches[2]);
$response->addHeader($name, $value);
} else {
// This is the status response
//echo "HEADER: ", trim($line), "\n";
if (preg_match('/^(HTTP\\/\\d\\.\\d) (\\d*) (.*)$/', trim($line), $matches)) {
$response->setStatus($matches[2]);
$response->setStatusMsg($matches[3]);
$response->setVersion($matches[1]);
}
}
}
} else {
$buffer[] = $line;
}
}
// The buffer is the HTTP Entity Body
$response->setBody(implode("\n", $buffer));
} else {
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($statusCode == 0) {
$response->setStatus(502);
$response->setStatusMsg('CURL Error');
} else {
$response->setStatus($statusCode);
$response->setStatusMsg('CURL Response');
}
}
return $response;
}