## Class THttpResponse

Description

Implements interfaces:

- ITextWriter

THttpResponse class

THttpResponse implements the mechanism for sending output to client users.

To output a string to client, use write(). By default, the output is buffered until flush() is called or the application ends. The output in the buffer can also be cleaned by clear(). To disable output buffering, set BufferOutput property to false.

To send cookies to client, use getCookies(). To redirect client browser to a new URL, use redirect(). To send a file to client, use writeFile().

By default, THttpResponse is registered with TApplication as the response module. It can be accessed via TApplication::getResponse().

THttpResponse may be configured in application configuration file as follows

<module id="response" class="System.Web.THttpResponse" CacheExpire="20" CacheControl="nocache" BufferOutput="true" />

where CacheExpire, CacheControl and BufferOutput are optional properties of THttpResponse.

THttpResponse sends charset header if either Charset or TGlobalization.Charset is set.

- since: 3.0
- version: $Id: THttpResponse.php 1980 2007-05-30 23:27:00Z knut $
- author: Qiang Xue <qiang.xue@gmail.com>

Located in /Web/THttpResponse.php (line 50)

    TComponent
       |
       --TApplicationComponent
          |
          --TModule
             |
             --THttpResponse

Method Summary
void __destruct ()
void addCookie (THttpCookie $cookie)
void appendHeader (string $value)
void appendLog (string $message, integer $messageType, [string $destination = ''], [string $extraHeaders = ''])
void clear ()
void createHtmlWriter ([string $type = null])
void createNewHtmlWriter (string $type, ITextWriter $writer)
void flush ()
void flushContent ()
THttpResponseAdapter getAdapter ()
boolean getBufferOutput ()
string getCacheControl ()
integer getCacheExpire ()
string getCharset ()
string getContents ()
string getContentType ()
THttpCookieCollection getCookies ()
boolean getHasAdapter ()
string getHtmlWriterType ()
integer getStatusCode ()
void httpRedirect (string $url)
void init (TXmlElement $config)
void redirect (string $url)
void reload ()
void removeCookie (THttpCookie $cookie)
void sendContentTypeHeader ()
void setAdapter (THttpResponseAdapter $adapter)
void setBufferOutput (boolean $value)
void setCacheControl (string $value)
void setCacheExpire (integer $value)
void setCharset (string $charset)
string setContentType (mixed $type)
void setHtmlWriterType (string $value)
void setStatusCode (integer $status)
void write (string $str)
void writeFile (string $fileName, [string $content = null], [string $mimeType = null], [array $headers = null])
Methods
Destructor __destruct (line 89)

Destructor.

Flushes any existing content in buffer.

- access: public

void __destruct ()
addCookie (line 440)

Sends a cookie.

Do not call this method directly. Operate with the result of getCookies instead.

- access: public

void addCookie (THttpCookie $cookie)

- THttpCookie $cookie: cook to be sent

appendHeader (line 415)

Sends a header.

- access: public

void appendHeader (string $value)

- string $value: header

appendLog (line 430)

Writes a log message into error log.

This method is simple wrapper of PHP function error_log.

- access: public
- see: http://us2.php.net/manual/en/function.error-log.php

void appendLog (string $message, integer $messageType, [string $destination = ''], [string $extraHeaders = ''])

- string $message: The error message that should be logged
- integer $messageType: where the error should go
- string $destination: The destination. Its meaning depends on the message parameter as described above
- string $extraHeaders: The extra headers. It's used when the message parameter is set to 1. This message type uses the same internal function as mail() does.

clear (line 404)

Clears any existing buffered content.

- access: public

void clear ()
createHtmlWriter (line 483)

Creates a new instance of HTML writer.

If the type of the HTML writer is not supplied, HtmlWriterType will be assumed.

- access: public

void createHtmlWriter ([string $type = null])

- string $type: type of the HTML writer to be created. If null, HtmlWriterType will be assumed.

createNewHtmlWriter (line 499)

Create a new html writer instance.

This method is used internally. Please use createHtmlWriter instead.

- access: public

void createNewHtmlWriter (string $type, ITextWriter $writer)

- string $type: type of HTML writer to be created.
- ITextWriter $writer: text writer holding the contents.

flush (line 352)

Flush the response contents and headers.

- access: public

void flush ()
flushContent (line 364)

Outputs the buffered content, sends content-type and charset header.

This method is used internally. Please use flush instead.

- access: public

void flushContent ()
getAdapter (line 106)

- return: response adapter, null if not exist.
- access: public

THttpResponseAdapter getAdapter ()
getBufferOutput (line 201)

- return: whether to enable output buffer
- access: public

boolean getBufferOutput ()
getCacheControl (line 152)

- return: cache control method to use for session pages
- access: public

string getCacheControl ()
getCacheExpire (line 136)

- return: time-to-live for cached session pages in minutes, this has no effect for nocache limiter. Defaults to 180.
- access: public

integer getCacheExpire ()
getCharset (line 185)

- return: output charset.
- access: public

string getCharset ()
getContents (line 395)

Returns the content in the output buffer.

The buffer will NOT be cleared after calling this method. Use clear() is you want to clear the buffer.

- return: output that is in the buffer.
- access: public

string getContents ()
getContentType (line 177)

- return: current content type
- access: public

string getContentType ()
getCookies (line 237)

- return: list of output cookies
- access: public

THttpCookieCollection getCookies ()
getHasAdapter (line 114)

- return: true if adapter exists, false otherwise.
- access: public

boolean getHasAdapter ()
getHtmlWriterType (line 465)

- return: the type of HTML writer to be used, defaults to THtmlWriter
- access: public

string getHtmlWriterType ()
getStatusCode (line 221)

- return: HTTP status code, defaults to 200
- access: public

integer getStatusCode ()
httpRedirect (line 329)

Redirect the browser to another URL and exists the current application.

This method is used internally. Please use redirect instead.

- access: public

void httpRedirect (string $url)

- string $url: URL to be redirected to. If the URL is a relative one, the base URL of the current request will be inserted at the beginning.

init (line 125)

Initializes the module.

This method is required by IModule and is invoked by application. It starts output buffer if it is enabled.

- access: public

void init (TXmlElement $config)

- TXmlElement $config: module configuration

Redefinition of:

TModule::init()
  Initializes the module.

redirect (line 315)

Redirects the browser to the specified URL.

The current application will be terminated after this method is invoked.

- access: public

void redirect (string $url)

- string $url: URL to be redirected to. If the URL is a relative one, the base URL of the current request will be inserted at the beginning.

reload (line 344)

Reloads the current page.

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

- access: public

void reload ()
removeCookie (line 457)

Deletes a cookie.

Do not call this method directly. Operate with the result of getCookies instead.

- access: public

void removeCookie (THttpCookie $cookie)

- THttpCookie $cookie: cook to be deleted

sendContentTypeHeader (line 375)

Sends content type header if charset is not empty.

- access: protected

void sendContentTypeHeader ()
setAdapter (line 98)

- access: public

void setAdapter (THttpResponseAdapter $adapter)

- THttpResponseAdapter $adapter: response adapter

setBufferOutput (line 210)

- access: public
- throws: TInvalidOperationException if session is started already

void setBufferOutput (boolean $value)

- boolean $value: whether to enable output buffer

setCacheControl (line 161)

- access: public

void setCacheControl (string $value)

- string $value: cache control method to use for session pages. Valid values include none/nocache/private/private_no_expire/public

setCacheExpire (line 144)

- access: public

void setCacheExpire (integer $value)

- integer $value: time-to-live for cached session pages in minutes, this has no effect for nocache limiter.

setCharset (line 193)

- access: public

void setCharset (string $charset)

- string $charset: output charset.

setContentType (line 169)

- return: content type, default is text/html
- access: public

string setContentType (mixed $type)
setHtmlWriterType (line 473)

- access: public

void setHtmlWriterType (string $value)

- string $value: the type of HTML writer to be used, may be the class name or the namespace

setStatusCode (line 229)

- access: public

void setStatusCode (integer $status)

- integer $status: HTTP status code

write (line 249)

Outputs a string.

It may not be sent back to user immediately if output buffer is enabled.

- access: public

void write (string $str)

- string $str: string to be output

writeFile (line 263)

Sends a file back to user.

Make sure not to output anything else after calling this method.

- access: public
- throws: TInvalidDataValueException if the file cannot be found

void writeFile (string $fileName, [string $content = null], [string $mimeType = null], [array $headers = null])

- string $fileName: file name
- string $content: content to be set. If null, the content will be read from the server file pointed to by $fileName.
- string $mimeType: mime type of the content.
- array $headers: list of headers to be sent. Each array element represents a header string (e.g. 'Content-Type: text/plain').

#### Inherited Methods

Inherited From TModule

> TModule::getID()
> TModule::init()
> TModule::setID()

Inherited From TApplicationComponent

> TApplicationComponent::getApplication()
> TApplicationComponent::getRequest()
> TApplicationComponent::getResponse()
> TApplicationComponent::getService()
> TApplicationComponent::getSession()
> TApplicationComponent::getUser()
> TApplicationComponent::publishAsset()
> TApplicationComponent::publishFilePath()

Inherited From TComponent

> TComponent::addParsedObject()
> TComponent::attachEventHandler()
> TComponent::canGetProperty()
> TComponent::canSetProperty()
> TComponent::createdOnTemplate()
> TComponent::detachEventHandler()
> TComponent::evaluateExpression()
> TComponent::evaluateStatements()
> TComponent::getEventHandlers()
> TComponent::getSubProperty()
> TComponent::hasEvent()
> TComponent::hasEventHandler()
> TComponent::hasProperty()
> TComponent::raiseEvent()
> TComponent::setSubProperty()
> TComponent::__get()
> TComponent::__set()

Documentation generated on Sun, 30 Sep 2007 19:16:17 -0400 by phpDocumentor 1.3.0RC4