Class THttpRequest

Description

Implements interfaces:

  • IteratorAggregate (internal interface)
  • ArrayAccess (internal interface)
  • Countable (internal interface)
  • 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,

  1.    if(isset($request['param1'])) ...
  2.    // equivalent to:
  3.    // if($request->contains('param1')) ...
To get the value of 'param1', use,
  1.    $value=$request['param1'];
  2.    // equivalent to:
  3.    //   $value=$request->itemAt('param1');
To traverse the user post data, use
  1.    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(). The format of the recognizable URLs is determined according to UrlManager. By default, the following two formats are recognized:

  1.  /index.php?ServiceID=ServiceParameter&Name1=Value1&Name2=Value2
  2.  /index.php/ServiceID,ServiceParameter/Name1,Value1/Name2,Value2
The first format is called 'Get' while the second 'Path', which is specified via UrlFormat. For advanced users who want to use their own URL formats, they can write customized URL management modules and install the managers as application modules and set UrlManager.

The ServiceID in the above URLs is as defined in the application configuration (e.g. the default page service's service ID is 'page'). As a consequence, your GET variable names should not conflict with the service IDs that your application supports.

THttpRequest also provides the cookies sent by the user, user information such as his browser capabilities, accepted languages, etc.

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

  • author: Qiang Xue <qiang.xue@gmail.com>
  • version: $Id: THttpRequest.php 3099 2012-01-29 11:48:14Z ctrlaltca@gmail.com $
  • since: 3.0

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

TComponent
   |
   --TApplicationComponent
      |
      --THttpRequest
Class Constant Summary
Method Summary
void add (mixed $key, mixed $value)
void clear ()
string constructUrl (string $serviceID, string $serviceParam, [array $getItems = null], [boolean $encodeAmpersand = true], [boolean $encodeGetItems = true])
boolean contains (mixed $key)
integer count ()
string getAbsoluteApplicationUrl ([boolean|null $forceSecureConnection = null])
string getAcceptTypes ()
string getApplicationUrl ()
string getBaseUrl ([boolean|null $forceSecureConnection = null])
array getBrowser ()
integer getCgiFix ()
string getContentType ([boolean $mimetypeOnly = true])
integer getCount ()
array getHeaders ([integer|null $case = null])
string getID ()
Iterator getIterator ()
array getKeys ()
string getPathInfo ()
string getQueryString ()
boolean getRequestResolved ()
string getRequestType ()
string getRequestUri ()
string getServerName ()
integer getServerPort ()
string getServiceID ()
array getUploadedFiles ()
string getUrlManager ()
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)
array parseUrl ()
mixed remove (mixed $key)
string resolveRequest (array $serviceIDs)
void setCgiFix (integer $value)
void setEnableCookieValidation (boolean $value)
void setID (string $value)
void setServiceID (string $value)
void setServiceParameter (string $value)
void setUrlManager (string $value)
void setUrlParamSeparator (string $value)
mixed stripSlashes (mixed &$data)
array toArray ()
Methods
add (line 791)

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 817)

Removes all items in the request.

  • access: public
void clear ()
constructUrl (line 642)

Constructs a URL that can be recognized by PRADO.

The actual construction work is done by the URL manager module. This method may append session information to the generated URL if needed. You may provide your own URL manager module by setting UrlManager to provide your own URL scheme.

Note, the constructed URL does not contain the protocol and hostname part. You may obtain an absolute URL by prepending the constructed URL with BaseUrl.

  • return: URL
  • see: TUrlManager::constructUrl
  • access: public
string constructUrl (string $serviceID, string $serviceParam, [array $getItems = null], [boolean $encodeAmpersand = true], [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 true.
  • boolean $encodeGetItems: whether to encode the GET parameters (their names and values), defaults to false.
contains (line 827)
  • return: whether the request contains an item with the specified key
  • access: public
boolean contains (mixed $key)
  • mixed $key: the key
count (line 761)

Returns the number of items in the request.

This method is required by Countable interface.

  • return: number of items in the request.
  • access: public
integer count ()

Implementation of:
Countable::count
getAbsoluteApplicationUrl (line 441)
  • return: entry script URL (w/ host part)
  • access: public
string getAbsoluteApplicationUrl ([boolean|null $forceSecureConnection = null])
  • boolean|null $forceSecureConnection: whether to use HTTPS instead of HTTP even if the current request is sent via HTTP or vice versa null - keep current schema true - force https false - force http
getAcceptTypes (line 521)
  • return: user browser accept types
  • access: public
string getAcceptTypes ()
getApplicationFilePath (line 449)
  • return: application entry script file path (processed w/ realpath())
  • access: public
string getApplicationFilePath ()
getApplicationUrl (line 426)
  • return: entry script URL (w/o host part)
  • access: public
string getApplicationUrl ()
getBaseUrl (line 414)
  • return: schema and hostname of the requested URL
  • access: public
string getBaseUrl ([boolean|null $forceSecureConnection = null])
  • boolean|null $forceSecureConnection: whether to use HTTPS instead of HTTP even if the current request is sent via HTTP or vice versa null - keep current schema true - force https false - force http
getBrowser (line 482)
  • return: user browser capabilities
  • see: get_browser
  • access: public
array getBrowser ()
getCgiFix (line 559)
integer getCgiFix ()
getContentType (line 330)
  • return: content type (e.g. 'application/json' or 'text/html; encoding=gzip') or null if not specified
  • access: public
string getContentType ([boolean $mimetypeOnly = true])
  • boolean $mimetypeOnly: whether to return only the mimetype (default: true)
getCookies (line 578)
  • return: list of cookies to be sent
  • access: public
THttpCookieCollection getCookies ()
getCount (line 751)
  • return: the number of items in the request
  • access: public
integer getCount ()
getEnableCookieValidation (line 542)
  • return: whether cookies should be validated. Defaults to false.
  • access: public
boolean getEnableCookieValidation ()
getEnvironmentVariables (line 620)
  • return: list of environment variables.
  • access: public
array getEnvironmentVariables ()
getHeaders (line 377)
  • access: public
array getHeaders ([integer|null $case = null])
  • integer|null $case: Either CASE_UPPER or CASE_LOWER or as is null (default)
getHttpProtocolVersion (line 368)
  • return: the requested http procolol. Blank string if not defined.
  • access: public
string getHttpProtocolVersion ()
getID (line 134)
  • return: id of this module
  • access: public
string getID ()
getIsSecureConnection (line 344)
  • return: if the request is sent via secure channel (https)
  • access: public
boolean getIsSecureConnection ()
getIterator (line 743)

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 ()

Implementation of:
IteratorAggregate::getIterator
getKeys (line 769)
  • return: the key list
  • access: public
array getKeys ()
getPathInfo (line 352)
  • return: part of the request URL after script name and before question mark.
  • access: public
string getPathInfo ()
getQueryString (line 360)
  • return: part of that request URL after the question mark
  • access: public
string getQueryString ()
getRequestResolved (line 697)
  • return: true if request is already resolved, false otherwise.
  • access: public
boolean getRequestResolved ()
getRequestType (line 321)
  • return: request type, can be GET, POST, HEAD, or PUT
  • access: public
string getRequestType ()
getRequestUri (line 402)
  • return: part of that request URL after the host info (including pathinfo and query string)
  • access: public
string getRequestUri ()
getServerName (line 457)
  • return: server name
  • access: public
string getServerName ()
getServerPort (line 465)
  • return: server port number
  • access: public
integer getServerPort ()
getServerVariables (line 612)
  • return: list of server variables.
  • access: public
array getServerVariables ()
getServiceID (line 705)
  • return: requested service ID
  • access: public
string getServiceID ()
getServiceParameter (line 722)
  • return: requested service parameter
  • access: public
string getServiceParameter ()
getUploadedFiles (line 604)
  • return: list of uploaded files.
  • access: public
array getUploadedFiles ()
getUrl (line 227)
  • return: the request URL
  • access: public
TUri getUrl ()
getUrlFormat (line 280)
  • return: the format of URLs. Defaults to THttpRequestUrlFormat::Get.
  • access: public
THttpRequestUrlFormat getUrlFormat ()
getUrlManager (line 251)
  • return: the ID of the URL manager module
  • access: public
string getUrlManager ()
getUrlManagerModule (line 272)
  • return: the URL manager module
  • access: public
TUrlManager getUrlManagerModule ()
getUrlParamSeparator (line 301)
  • return: separator used to separate GET variable name and value when URL format is Path. Defaults to comma ','.
  • access: public
string getUrlParamSeparator ()
getUrlReferrer (line 473)
  • return: URL referrer, null if not present
  • access: public
string getUrlReferrer ()
getUserAgent (line 497)
  • return: user agent
  • access: public
string getUserAgent ()
getUserHost (line 513)
  • return: user host name, null if cannot be determined
  • access: public
string getUserHost ()
getUserHostAddress (line 505)
  • return: user IP address
  • access: public
string getUserHostAddress ()
getUserLanguages (line 534)

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 152)

Initializes the module.

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

  • access: public
void init (TXmlElement $config)
itemAt (line 780)

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 846)

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

Implementation of:
ArrayAccess::offsetExists
offsetGet (line 857)

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.

Implementation of:
ArrayAccess::offsetGet
offsetSet (line 868)

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

Implementation of:
ArrayAccess::offsetSet
offsetUnset (line 878)

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

Implementation of:
ArrayAccess::offsetUnset
parseUrl (line 659)

Parses the request URL and returns an array of input parameters (excluding GET variables).

You may override this method to support customized URL format.

  • return: list of input parameters, indexed by parameter names
  • see: TUrlManager::parseUrl
  • access: protected
array parseUrl ()
remove (line 802)

Removes an item from the request by its key.

  • return: the removed value, null if no such key exists.
  • throws: TInvalidOperationException if the item cannot be removed
  • access: public
mixed remove (mixed $key)
  • mixed $key: the key of the item to be removed
resolveRequest (line 674)

Resolves the requested service.

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.

string resolveRequest (array $serviceIDs)
  • array $serviceIDs: list of valid service IDs
setCgiFix (line 570)

Enable this, if you're using PHP via CGI with php.ini setting "cgi.fix_pathinfo=1"

and have trouble with friendly URL feature. Enable this only if you really know what you are doing!

void setCgiFix (integer $value)
  • integer $value: enable bitwise to use ORIG_PATH_INFO and/or ORIG_SCRIPT_NAME.
setEnableCookieValidation (line 550)
  • access: public
void setEnableCookieValidation (boolean $value)
  • boolean $value: whether cookies should be validated.
setID (line 142)
  • access: public
void setID (string $value)
  • string $value: id of this module
setServiceID (line 714)

Sets the requested service ID.

  • access: public
void setServiceID (string $value)
  • string $value: requested service ID
setServiceParameter (line 731)

Sets the requested service parameter.

  • access: public
void setServiceParameter (string $value)
  • string $value: requested service parameter
setUrlFormat (line 293)

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 (THttpRequestUrlFormat $value)
setUrlManager (line 264)

Sets the URL manager module.

By default, TUrlManager is used for managing URLs. You may specify a different module for URL managing tasks by loading it as an application module and setting this property with the module ID.

  • access: public
void setUrlManager (string $value)
  • string $value: the ID of the URL manager module
setUrlParamSeparator (line 310)
  • throws: TInvalidDataValueException if the separator is not a single character
  • access: public
void setUrlParamSeparator (string $value)
  • string $value: separator used to separate GET variable name and value when URL format is Path.
stripSlashes (line 219)

Strips slashes from input data.

This method is applied when magic quotes is enabled.

  • return: processed data
  • access: public
mixed stripSlashes (mixed &$data)
  • mixed &$data: input data to be processed
toArray (line 835)
  • 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::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::__call()
TComponent::__get()
TComponent::__set()
TComponent::__sleep()
TComponent::__wakeup()
Class Constants
CGIFIX__PATH_INFO = 1 (line 73)
CGIFIX__SCRIPT_NAME = 2 (line 74)

Documentation generated on Mon, 25 Jun 2012 14:38:22 +0200 by phpDocumentor 1.4.3