## Class THttpRequest

Description

Implements interfaces:

- IModule

THttpRequest class

THttpRequest provides storage and access scheme for user request sent via HTTP. It also encapsulates a uniform way to parse and construct URLs.

User post data can be retrieved from THttpRequest by using it like an associative array. For example, to test if a user supplies a variable named 'param1', you can use,

       if(isset($request['param1'])) ...
       // equivalent to:
       // if($request->contains('param1')) ...

To get the value of 'param1', use,

       $value=$request['param1'];
       // equivalent to:
       //   $value=$request->itemAt('param1');

To traverse the user post data, use

       foreach($request as $name=>$value) ...

Note, POST and GET variables are merged together in THttpRequest. If a variable name appears in both POST and GET data, then POST data takes precedence.

To construct a URL that can be recognized by Prado, use constructUrl(). THttpRequest also provides the cookies sent by the user, user information such as his browser capabilities, accepted languages, etc. Currently, THttpRequest recognizes the following URL format:

     /index.php?ServiceID=ServiceParameter

where ServiceID is as defined in the application configuration (e.g. the default page service's service ID is 'page'). Therefore, your GET variable names should not conflict with the service IDs that your application supports.

By default, THttpRequest is registered with TApplication as the request module. It can be accessed via TApplication::getRequest().

- since: 3.0
- version: $Revision: $ $Date: $
- author: Qiang Xue <qiang.xue@gmail.com>

Located in /Web/THttpRequest.php (line 60)

    TComponent
       |
       --TApplicationComponent
          |
          --THttpRequest

Class Constant Summary
URL_PARAM_SEPARATOR = ','
Method Summary
void add (mixed $key, mixed $value)
void clear ()
string constructUrl (string $serviceID, string $serviceParam, [array $getItems = null], [boolean $encodeAmpersand = false], [boolean $encodeGetItems = true])
boolean contains (mixed $key)
string getAcceptTypes ()
string getApplicationFilePath ()
string getApplicationUrl ()
array getAvailableServices ()
array getBrowser ()
THttpCookieCollection getCookies ()
integer getCount ()
boolean getEnableCookieValidation ()
array getEnvironmentVariables ()
string getID ()
boolean getIsSecureConnection ()
Iterator getIterator ()
array getKeys ()
string getPathInfo ()
string getQueryString ()
string getRequestType ()
string getRequestUri ()
string getServerName ()
integer getServerPort ()
array getServerVariables ()
string getServiceID ()
string getServiceParameter ()
array getUploadedFiles ()
TUri getUrl ()
string getUrlFormat ()
string getUrlReferrer ()
string getUserAgent ()
string getUserHost ()
string getUserHostAddress ()
array getUserLanguages ()
void init (TXmlElement $config)
mixed itemAt (mixed $key)
boolean offsetExists (mixed $offset)
mixed offsetGet (integer $offset)
void offsetSet (integer $offset, mixed $item)
void offsetUnset (mixed $offset)
mixed remove (mixed $key)
void resolveRequest ()
void setAvailableServices (array $services)
void setEnableCookieValidation (boolean $value)
void setID (string $value)
void setServiceID (string $value)
void setServiceParameter (string $value)
void setUrlFormat (string $value)
void stripSlashes (mixed &$data, mixed 1)
array toArray ()
Methods
add (line 632)

Adds an item into the request.

Note, if the specified key already exists, the old value will be overwritten.

- access: public

void add (mixed $key, mixed $value)

- mixed $key: key
- mixed $value: value

clear (line 658)

Removes all items in the request.

- access: public

void clear ()
constructUrl (line 461)

Constructs a URL that is recognizable by Prado.

You may override this method to provide your own way of URL formatting. The URL is constructed as the following format: /entryscript.php?serviceID=serviceParameter&get1=value1&...

- return: URL
- access: public

string constructUrl (string $serviceID, string $serviceParam, [array $getItems = null], [boolean $encodeAmpersand = false], [boolean $encodeGetItems = true])

- string $serviceID: service ID
- string $serviceParam: service parameter
- array $getItems: GET parameters, null if not needed
- boolean $encodeAmpersand: whether to encode the ampersand in URL, defaults to false.
- boolean $encodeGetItems: whether to encode the GET parameters (their names and values), defaults to true.

contains (line 668)

- return: whether the request contains an item with the specified key
- access: public

boolean contains (mixed $key)

- mixed $key: the key

getAcceptTypes (line 365)

- return: user browser accept types
- access: public

string getAcceptTypes ()
getApplicationFilePath (line 300)

- return: application entry script file path (processed w/ realpath())
- access: public

string getApplicationFilePath ()
getApplicationUrl (line 292)

- return: entry script URL (w/o host part)
- access: public

string getApplicationUrl ()
getAvailableServices (line 536)

- return: IDs of the available services
- access: public

array getAvailableServices ()
getBrowser (line 333)

- return: user browser capabilities
- access: public
- see: get_browser

array getBrowser ()
getCookies (line 402)

- return: list of cookies to be sent
- access: public

THttpCookieCollection getCookies ()
getCount (line 602)

- return: the number of items in the request
- access: public

integer getCount ()
getEnableCookieValidation (line 386)

- return: whether cookies should be validated. Defaults to false.
- access: public

boolean getEnableCookieValidation ()
getEnvironmentVariables (line 444)

- return: list of environment variables.
- access: public

array getEnvironmentVariables ()
getID (line 114)

- return: id of this module
- access: public

string getID ()
getIsSecureConnection (line 260)

- return: if the request is sent via secure channel (https)
- access: public

boolean getIsSecureConnection ()
getIterator (line 594)

Returns an iterator for traversing the items in the list.

This method is required by the interface IteratorAggregate.

- return: an iterator for traversing the items in the list.
- access: public

Iterator getIterator ()
getKeys (line 610)

- return: the key list
- access: public

array getKeys ()
getPathInfo (line 268)

- return: part of the request URL after script name and before question mark.
- access: public

string getPathInfo ()
getQueryString (line 276)

- return: part of that request URL after the question mark
- access: public

string getQueryString ()
getRequestType (line 252)

- return: request type, can be GET, POST, HEAD, or PUT
- access: public

string getRequestType ()
getRequestUri (line 284)

- return: part of that request URL after the host info (including pathinfo and query string)
- access: public

string getRequestUri ()
getServerName (line 308)

- return: server name
- access: public

string getServerName ()
getServerPort (line 316)

- return: server port number
- access: public

integer getServerPort ()
getServerVariables (line 436)

- return: list of server variables.
- access: public

array getServerVariables ()
getServiceID (line 552)

- return: requested service ID
- access: public

string getServiceID ()
getServiceParameter (line 571)

- return: requested service parameter
- access: public

string getServiceParameter ()
getUploadedFiles (line 428)

- return: list of uploaded files.
- access: public

array getUploadedFiles ()
getUrl (line 207)

- return: the request URL
- access: public

TUri getUrl ()
getUrlFormat (line 231)

- return: the format of URLs. Defaults to 'Get'.
- access: public

string getUrlFormat ()
getUrlReferrer (line 324)

- return: URL referrer, null if not present
- access: public

string getUrlReferrer ()
getUserAgent (line 341)

- return: user agent
- access: public

string getUserAgent ()
getUserHost (line 357)

- return: user host name, null if cannot be determined
- access: public

string getUserHost ()
getUserHostAddress (line 349)

- return: user IP address
- access: public

string getUserHostAddress ()
getUserLanguages (line 378)

Returns a list of user preferred languages.

The languages are returned as an array. Each array element represents a single language preference. The languages are ordered according to user preferences. The first language is the most preferred.

- return: list of user preferred languages.
- access: public

array getUserLanguages ()
init (line 132)

Initializes the module.

This method is required by IModule and is invoked by application.

- access: public

void init (TXmlElement $config)

- TXmlElement $config: module configuration

itemAt (line 621)

Returns the item with the specified key.

This method is exactly the same as offsetGet.

- return: the element at the offset, null if no element is found at the offset
- access: public

mixed itemAt (mixed $key)

- mixed $key: the key

offsetExists (line 687)

Returns whether there is an element at the specified offset.

This method is required by the interface ArrayAccess.

- access: public

boolean offsetExists (mixed $offset)

- mixed $offset: the offset to check on

offsetGet (line 698)

Returns the element at the specified offset.

This method is required by the interface ArrayAccess.

- return: the element at the offset, null if no element is found at the offset
- access: public

mixed offsetGet (integer $offset)

- integer $offset: the offset to retrieve element.

offsetSet (line 709)

Sets the element at the specified offset.

This method is required by the interface ArrayAccess.

- access: public

void offsetSet (integer $offset, mixed $item)

- integer $offset: the offset to set element
- mixed $item: the element value

offsetUnset (line 719)

Unsets the element at the specified offset.

This method is required by the interface ArrayAccess.

- access: public

void offsetUnset (mixed $offset)

- mixed $offset: the offset to unset element

remove (line 643)

Removes an item from the request by its key.

- return: the removed value, null if no such key exists.
- access: public
- throws: TInvalidOperationException if the item cannot be removed

mixed remove (mixed $key)

- mixed $key: the key of the item to be removed

resolveRequest (line 518)

Resolves the requested servie.

This method implements a URL-based service resolution. A URL in the format of /index.php?sp=serviceID.serviceParameter will be resolved with the serviceID and the serviceParameter. You may override this method to provide your own way of service resolution.

- access: protected
- see: THttpRequest::constructUrl()

void resolveRequest ()
setAvailableServices (line 544)

- access: public

void setAvailableServices (array $services)

- array $services: IDs of the available services

setEnableCookieValidation (line 394)

- access: public

void setEnableCookieValidation (boolean $value)

- boolean $value: whether cookies should be validated.

setID (line 122)

- access: public

void setID (string $value)

- string $value: id of this module

setServiceID (line 563)

Sets the requested service ID.

- access: protected

void setServiceID (string $value)

- string $value: requested service ID

setServiceParameter (line 582)

Sets the requested service parameter.

- access: protected

void setServiceParameter (string $value)

- string $value: requested service parameter

setUrlFormat (line 244)

Sets the format of URLs constructed and interpretted by the request module.

A 'Get' URL format is like index.php?name1=value1&name2=value2 while a 'Path' URL format is like index.php/name1,value1/name2,value. Changing the UrlFormat will affect constructUrl and how GET variables are parsed.

- access: public

void setUrlFormat (string $value)

- string $value: the format of URLs. Valid values include 'Path' and 'Get'.

stripSlashes (line 199)

Strips slashes from input data.

This method is applied when magic quotes is enabled.

- access: public

void stripSlashes (mixed &$data, mixed 1)

- mixed 1: processed data
- mixed &$data: input data to be processed

toArray (line 676)

- return: the list of items in array
- access: public

array toArray ()

#### Inherited Methods

Inherited From TApplicationComponent

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

Inherited From TComponent

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

Class Constants
URL_PARAM_SEPARATOR = ',' (line 65)

Separator used to separate GET variable name and value when URL format is Path.

Documentation generated on Sun, 04 Jun 2006 18:59:30 -0400 by phpDocumentor 1.3.0RC4