本文整理汇总了PHP中Zend\Http\Response::renderStatusLine方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::renderStatusLine方法的具体用法?PHP Response::renderStatusLine怎么用?PHP Response::renderStatusLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Http\Response
的用法示例。
在下文中一共展示了Response::renderStatusLine方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: plugin_preview_action
function plugin_preview_action()
{
global $vars;
$page = isset($vars['page']) ? $vars['page'] : '';
$modified = 0;
$response = new Response();
if (!empty($page)) {
$wiki = Factory::Wiki($page);
if ($wiki->isReadable()) {
$source = $wiki->get();
array_splice($source, 10);
$response->setStatusCode(Response::STATUS_CODE_200);
$response->setContent('<' . '?xml version="1.0" encoding="UTF-8"?' . ">\n" . RendererFactory::factory($source));
$headers = Header::getHeaders('text/xml', $wiki->time());
} else {
$response->setStatusCode(Response::STATUS_CODE_404);
$headers = Header::getHeaders('text/xml');
}
} else {
$response->setStatusCode(Response::STATUS_CODE_404);
$headers = Header::getHeaders('text/xml');
}
$response->getHeaders()->addHeaders($headers);
header($response->renderStatusLine());
foreach ($response->getHeaders() as $_header) {
header($_header->toString());
}
echo $response->getBody();
exit;
}
示例3: redirect
/**
* Performs a HTTP redirection to specified URL with additional data.
* It may generate redirected request using GET or POST HTTP method.
* The function never returns.
*
* @param string $url URL to redirect to
* @param array $params additional variable/value pairs to send
* @param Response $response
* @param string $method redirection method ('GET' or 'POST')
*/
public static function redirect($url, $params = null, Response $response = null, $method = 'GET')
{
$url = self::absoluteUrl($url);
$body = "";
if (null === $response) {
$response = new Response();
}
if ($method == 'POST') {
$body = "<html><body onLoad=\"document.forms[0].submit();\">\n";
$body .= "<form method=\"POST\" action=\"{$url}\">\n";
if (is_array($params) && count($params) > 0) {
foreach ($params as $key => $value) {
$body .= '<input type="hidden" name="' . $key . '" value="' . $value . "\">\n";
}
}
$body .= "<input type=\"submit\" value=\"Continue OpenID transaction\">\n";
$body .= "</form></body></html>\n";
} else {
if (is_array($params) && count($params) > 0) {
if (strpos($url, '?') === false) {
$url .= '?' . self::paramsToQuery($params);
} else {
$url .= '&' . self::paramsToQuery($params);
}
}
}
if (!empty($body)) {
$response->setContent($body);
} elseif (headers_sent()) {
$response->setContent("<script language=\"JavaScript\"" . " type=\"text/javascript\">window.location='{$url}';" . "</script>");
}
$response->setStatusCode(302);
$response->headers()->addHeaderLine('Location', $url);
if (!headers_sent()) {
header($response->renderStatusLine());
foreach ($response->headers() as $header) {
header($header->toString());
}
}
echo $response->getBody();
if (self::$exitOnRedirect) {
exit;
}
}
示例4: writeResponse
/**
* 出力
* @param array $headers ヘッダー(別途Header::getHeaders()で指定すること)
* @param int $status ステータスコード
* @param string $body 内容
* @return void
*/
public static function writeResponse($headers, $status = Response::STATUS_CODE_200, $body = '')
{
global $_string;
// なぜかこの行を出力しないと503エラーが起きる
echo "";
// レスポンスをコンストラクト
$response = new Response();
if (!empty($body)) {
if ($status == Response::STATUS_CODE_200 && isset($headers['If-None-Match']) && !isset($headers['ETag'])) {
// Modifiedヘッダーが出力されてない場合、出力内容からETagを生成
// 負荷対策にはならないが転送量を抑えることができる
$hash = md5($body);
if (preg_match('/' . $hash . '/', $headers['If-None-Match'])) {
$status = Response::STATUS_CODE_304;
}
$headers['Etag'] = $hash;
} else {
if ($status == Response::STATUS_CODE_401) {
// レスポンスコードが401の場合、認証画面を出力
$headers['WWW-Authenticate'] = Auth::getAuthHeader();
}
}
// 内容が存在する場合容量をContent-Lengthヘッダーに出力
// if (!isset($headers['Content-Length'])){
$headers['Content-Length'] = strlen($body);
// }
// レスポンスに内容を追加
$response->setContent($body);
}
// ajaxで送信した時に、net::ERR_CONTENT_LENGTH_MISMATCHエラーが発生するので、
// その場合、Content Lengthヘッダーを出力しない
if (IS_AJAX) {
unset($headers['Content-Length']);
}
// ステータスコードを出力
$response->setStatusCode($status);
// ヘッダーをソート
ksort($headers);
// ヘッダーを指定
$response->getHeaders()->addHeaders($headers);
// ヘッダー出力をチェック
if (headers_sent($file, $line)) {
die(sprintf('Header::writeResponse(): ' . $_string['header_sent'], Utility::htmlsc($file), $line));
exit;
}
// ステータスコードを出力
header($response->renderStatusLine());
// ヘッダーを出力
foreach ($response->getHeaders() as $_header) {
header($_header->toString());
}
if (!empty($body)) {
// 内容を出力
echo $response->getBody();
}
// 出力バッファをフラッシュ
flush();
// 終了
exit;
}
示例5: notAuth
/**
* 認証要求
* @return void
*/
public static function notAuth($realm)
{
global $_string, $_title, $_button, $vars;
$response = new Response();
// URLが空の場合、ページのアドレスか、スクリプトのアドレスを返す
if (empty($url)) {
$url = isset($vars['page']) ? Router::get_resolve_uri(null, $vars['page']) : Router::get_script_uri();
}
$s_url = self::htmlsc($url);
$response->setStatusCode(Response::STATUS_CODE_301);
$response->getHeaders()->addHeaderLine('Location', $s_url);
$html = array();
$html[] = '<!doctype html>';
$html[] = '<html>';
$html[] = '<head>';
$html[] = '<meta charset="utf-8">';
$html[] = '<meta name="robots" content="noindex,nofollow,noarchive,noodp,noydir" />';
if (!DEBUG) {
$html[] = '<meta http-equiv="refresh" content="' . $time . '; URL=' . $s_url . '" />';
}
$html[] = '<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/' . Render::TWITTER_BOOTSTRAP_VER . '/css/bootstrap.min.css" type="text/css" />';
$html[] = '<title>' . $_title['redirect'] . '</title>';
$html[] = '</head>';
$html[] = '<body>';
$html[] = '<div class="container">';
$html[] = '<p class="alert alert-success">';
$html[] = '<span class="glyphicon glyphicon-info-sign"></span>';
$html[] = $_string['redirect1'] . '<br />';
$html[] = sprintf($_string['redirect2'], $s_url);
if (!DEBUG) {
$html[] = '<br />NOTICE: No auto redirect when Debug mode.';
}
$html[] = '</p>';
$html[] = '</div>';
$html[] = '</body>';
$html[] = '</html>';
$content = join("\n", $html);
$response->getHeaders()->addHeaderLine('Content-Length', strlen($content));
$response->setContent($content);
if (!headers_sent()) {
header($response->renderStatusLine());
foreach ($response->getHeaders() as $header) {
header($header->toString());
}
}
echo $response->getBody();
exit;
}
示例6: prepareResponse
/**
* Prepare a solarium response from the given request and client
* response
*
* @throws HttpException
* @param Request $request
* @param \Zend\Http\Response $response
* @return Response
*/
protected function prepareResponse($request, $response)
{
if ($response->isClientError()) {
throw new HttpException($response->getReasonPhrase(), $response->getStatusCode());
}
if ($request->getMethod() == Request::METHOD_HEAD) {
$data = '';
} else {
$data = $response->getBody();
}
// this is used because in ZF2 status line isn't in the headers anymore
$headers = array($response->renderStatusLine());
return new Response($data, $headers);
}
示例7: sendResponse
private function sendResponse(Response $response)
{
foreach ($response->getHeaders() as $header) {
if ($header instanceof MultipleHeaderInterface) {
header($header->toString(), false);
continue;
}
header($header->toString());
}
$status = $response->renderStatusLine();
header($status);
echo $response->getContent();
}