PHP Класс Prado\Web\THttpResponse

THttpResponse implements the mechanism for sending output to client users. To output a string to client, use {@link write()}. By default, the output is buffered until {@link flush()} is called or the application ends. The output in the buffer can also be cleaned by {@link clear()}. To disable output buffering, set BufferOutput property to false. To send cookies to client, use {@link getCookies()}. To redirect client browser to a new URL, use {@link redirect()}. To send a file to client, use {@link writeFile()}. By default, THttpResponse is registered with {@link TApplication} as the response module. It can be accessed via {@link TApplication::getResponse()}. THttpResponse may be configured in application configuration file as follows where {@link getCacheExpire CacheExpire}, {@link getCacheControl CacheControl} and {@link getBufferOutput BufferOutput} are optional properties of THttpResponse. THttpResponse sends charset header if either {@link setCharset() Charset} or {@link TGlobalization::setCharset() TGlobalization.Charset} is set. Since 3.1.2, HTTP status code can be set with the {@link setStatusCode StatusCode} property. Note: Some HTTP Status codes can require additional header or body information. So, if you use {@link setStatusCode StatusCode} in your application, be sure to add theses informations. E.g : to make an http authentication : public function clickAuth ($sender, $param) { $response=$this->getResponse(); $response->setStatusCode(401); $response->appendHeader('WWW-Authenticate: Basic realm="Test"'); } This event handler will sent the 401 status code (Unauthorized) to the browser, with the WWW-Authenticate header field. This will force the browser to ask for a username and a password.
С версии: 3.0
Автор: Qiang Xue ([email protected])
Наследование: extends Prado\TModule, implements Prado\IO\ITextWriter
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
__destruct ( ) Destructor.
addCookie ( $cookie ) Sends a cookie.
appendHeader ( $value, $replace = true ) Sends a header.
appendLog ( $message, $messageType, $destination = '', $extraHeaders = '' ) Writes a log message into error log.
clear ( ) Clears any existing buffered content.
createHtmlWriter ( $type = null ) Creates a new instance of HTML writer.
createNewHtmlWriter ( $type, $writer ) Create a new html writer instance.
ensureHeadersSent ( ) Ensures that HTTP response and content-type headers are sent
flush ( $continueBuffering = true ) Flush the response contents and headers.
flushContent ( $continueBuffering = true ) Outputs the buffered content, sends content-type and charset header.
getAdapter ( ) : THttpResponseAdapter
getBufferOutput ( ) : boolean
getCacheControl ( ) : string
getCacheExpire ( ) : integer
getCharset ( ) : string | boolean
getContentType ( ) : string
getContents ( ) : string Returns the content in the output buffer.
getCookies ( ) : THttpCookieCollection
getHasAdapter ( ) : boolean
getHeaders ( $case = null ) : array
getHtmlWriterType ( ) : string
getStatusCode ( ) : integer
getStatusReason ( )
httpRedirect ( $url ) Redirect the browser to another URL and exists the current application.
init ( $config ) Initializes the module.
redirect ( $url ) Redirects the browser to the specified URL.
reload ( ) Reloads the current page.
removeCookie ( $cookie ) Deletes a cookie.
setAdapter ( THttpResponseAdapter $adapter )
setBufferOutput ( $value )
setCacheControl ( $value )
setCacheExpire ( $value )
setCharset ( $charset )
setContentType ( $type ) : string
setHtmlWriterType ( $value )
setStatusCode ( $status, $reason = null ) Set the HTTP status code for the response.
write ( $str ) Outputs a string.
writeFile ( $fileName, $content = null, $mimeType = null, $headers = null, $forceDownload = true, $clientFileName = null, $fileSize = null ) Sends a file back to user.

Защищенные методы

Метод Описание
ensureContentTypeHeaderSent ( ) Ensures that the HTTP header with the status code and status reason are sent
ensureHttpHeaderSent ( ) Ensures that the HTTP header with the status code and status reason are sent
sendContentTypeHeader ( ) Sends content type header with optional charset.
sendHttpHeader ( ) Send the HTTP header with the status code (defaults to 200) and status reason (defaults to OK)

Описание методов

__destruct() публичный метод

Flushes any existing content in buffer.
public __destruct ( )

addCookie() публичный метод

Do not call this method directly. Operate with the result of {@link getCookies} instead.
public addCookie ( $cookie )

appendHeader() публичный метод

Sends a header.
public appendHeader ( $value, $replace = true )

appendLog() публичный метод

This method is simple wrapper of PHP function error_log.
См. также: http://us2.php.net/manual/en/function.error-log.php
public appendLog ( $message, $messageType, $destination = '', $extraHeaders = '' )

clear() публичный метод

Clears any existing buffered content.
public clear ( )

createHtmlWriter() публичный метод

If the type of the HTML writer is not supplied, {@link getHtmlWriterType HtmlWriterType} will be assumed.
public createHtmlWriter ( $type = null )

createNewHtmlWriter() публичный метод

This method is used internally. Please use {@link createHtmlWriter} instead.
public createNewHtmlWriter ( $type, $writer )

ensureContentTypeHeaderSent() защищенный метод

Ensures that the HTTP header with the status code and status reason are sent

ensureHeadersSent() публичный метод

Ensures that HTTP response and content-type headers are sent
public ensureHeadersSent ( )

ensureHttpHeaderSent() защищенный метод

Ensures that the HTTP header with the status code and status reason are sent
protected ensureHttpHeaderSent ( )

flush() публичный метод

Flush the response contents and headers.
public flush ( $continueBuffering = true )

flushContent() публичный метод

This method is used internally. Please use {@link flush} instead.
public flushContent ( $continueBuffering = true )

getAdapter() публичный метод

public getAdapter ( ) : THttpResponseAdapter
Результат THttpResponseAdapter response adapter, null if not exist.

getBufferOutput() публичный метод

public getBufferOutput ( ) : boolean
Результат boolean whether to enable output buffer

getCacheControl() публичный метод

public getCacheControl ( ) : string
Результат string cache control method to use for session pages

getCacheExpire() публичный метод

public getCacheExpire ( ) : integer
Результат integer time-to-live for cached session pages in minutes, this has no effect for nocache limiter. Defaults to 180.

getCharset() публичный метод

public getCharset ( ) : string | boolean
Результат string | boolean output charset.

getContentType() публичный метод

public getContentType ( ) : string
Результат string current content type

getContents() публичный метод

The buffer will NOT be cleared after calling this method. Use {@link clear()} is you want to clear the buffer.
public getContents ( ) : string
Результат string output that is in the buffer.

getCookies() публичный метод

public getCookies ( ) : THttpCookieCollection
Результат THttpCookieCollection list of output cookies

getHasAdapter() публичный метод

public getHasAdapter ( ) : boolean
Результат boolean true if adapter exists, false otherwise.

getHeaders() публичный метод

public getHeaders ( $case = null ) : array
Результат array

getHtmlWriterType() публичный метод

public getHtmlWriterType ( ) : string
Результат string the type of HTML writer to be used, defaults to THtmlWriter

getStatusCode() публичный метод

public getStatusCode ( ) : integer
Результат integer HTTP status code, defaults to 200

getStatusReason() публичный метод

public getStatusReason ( )

httpRedirect() публичный метод

This method is used internally. Please use {@link redirect} instead.
С версии: 3.1.5 You can set the set {@link setStatusCode StatusCode} to a value between 300 and 399 before calling this function to change the type of redirection. If not specified, StatusCode will be 302 (Found) by default
public httpRedirect ( $url )

init() публичный метод

This method is required by IModule and is invoked by application. It starts output buffer if it is enabled.
public init ( $config )

redirect() публичный метод

The current application will be terminated after this method is invoked.
public redirect ( $url )

reload() публичный метод

The effect of this method call is the same as user pressing the refresh button on his browser (without post data).
public reload ( )

removeCookie() публичный метод

Do not call this method directly. Operate with the result of {@link getCookies} instead.
public removeCookie ( $cookie )

sendContentTypeHeader() защищенный метод

Sends content type header with optional charset.
protected sendContentTypeHeader ( )

sendHttpHeader() защищенный метод

Send the HTTP header with the status code (defaults to 200) and status reason (defaults to OK)
protected sendHttpHeader ( )

setAdapter() публичный метод

public setAdapter ( THttpResponseAdapter $adapter )
$adapter THttpResponseAdapter

setBufferOutput() публичный метод

public setBufferOutput ( $value )

setCacheControl() публичный метод

public setCacheControl ( $value )

setCacheExpire() публичный метод

public setCacheExpire ( $value )

setCharset() публичный метод

public setCharset ( $charset )

setContentType() публичный метод

public setContentType ( $type ) : string
Результат string content type, default is text/html

setHtmlWriterType() публичный метод

public setHtmlWriterType ( $value )

setStatusCode() публичный метод

The code and its reason will be sent to client using the currently requested http protocol version (see {@link THttpRequest::getHttpProtocolVersion}) Keep in mind that HTTP/1.0 clients might not understand all status codes from HTTP/1.1
public setStatusCode ( $status, $reason = null )

write() публичный метод

It may not be sent back to user immediately if output buffer is enabled.
public write ( $str )

writeFile() публичный метод

Make sure not to output anything else after calling this method.
public writeFile ( $fileName, $content = null, $mimeType = null, $headers = null, $forceDownload = true, $clientFileName = null, $fileSize = null )