本文整理汇总了PHP中Zend\Http\Response::setVersion方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::setVersion方法的具体用法?PHP Response::setVersion怎么用?PHP Response::setVersion使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Http\Response
的用法示例。
在下文中一共展示了Response::setVersion方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testResponseCanRenderStatusLine
public function testResponseCanRenderStatusLine()
{
$response = new Response();
$response->setVersion(1.1);
$response->setStatusCode(Response::STATUS_CODE_404);
$this->assertEquals('HTTP/1.1 404 Not Found', $response->renderStatusLine());
$response->setReasonPhrase('Foo Bar');
$this->assertEquals('HTTP/1.1 404 Foo Bar', $response->renderStatusLine());
}
示例2: buildResponse
private function buildResponse($format, HttpResponse $httpResponse, OAuthResponse $oauthResponse)
{
$httpResponse->setVersion($oauthResponse->version);
$httpResponse->setStatusCode($oauthResponse->getStatusCode());
$headers = $httpResponse->getHeaders();
foreach ($oauthResponse->getHttpHeaders() as $name => $value) {
$headers->addHeaderLine(sprintf('%s: %s', $name, $value));
}
switch ($format) {
case 'json':
$headers->addHeaderLine('Content-Type: application/json');
$httpResponse->setContent(json_encode($oauthResponse->getParameters()));
break;
case 'xml':
$headers->addHeaderLine('Content-Type: text/xml');
$xml = new SimpleXMLElement('<response/>');
foreach ($oauthResponse->getParameters() as $key => $param) {
$xml->addChild($key, $param);
}
$httpResponse->setContent($xml->asXML());
break;
default:
throw new RuntimeException('Invalid format provided: ' . $format);
}
return $httpResponse;
}