PRADO Component Framework for PHP 5
  • Home
  • About
  • Testimonials
  • Demos
  • Download
  • Documentation
  • Forum
  • Development
  • Tutorials
  • Class Docs
  • API Manual
  • Wiki

Packages

  • None
  • System
    • Caching
    • Collections
    • Data
      • ActiveRecord
        • Relations
        • Scaffold
          • InputBuilder
      • Commom
        • Sqlite
      • Common
        • Mssql
        • Mysql
        • Oracle
        • Pgsql
        • Sqlite
      • DataGateway
      • SqlMap
        • Configuration
        • Statements
    • Exceptions
    • I18N
    • IO
    • Security
    • Util
    • Web
      • Javascripts
      • Services
      • UI
        • ActiveControls
        • WebControls
    • Xml
  • Wsat
    • pages
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo

Class THttpRequest

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 THttpRequest::constructUrl(). The format of the recognizable URLs is determined according to setUrlManager UrlManager. By default, the following two formats are recognized:

/index.php?ServiceID=ServiceParameter&Name1=Value1&Name2=Value2
/index.php/ServiceID,ServiceParameter/Name1,Value1/Name2,Value2

The first format is called 'Get' while the second 'Path', which is specified via setUrlFormat 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 setUrlManager 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().

TComponent
Extended by TApplicationComponent
Extended by THttpRequest implements IteratorAggregate, ArrayAccess, Countable, IModule
Package: System\Web
Copyright: Copyright © 2005-2014 PradoSoft
License: http://www.pradosoft.com/license/
Author: Qiang Xue <qiang.xue@gmail.com>
Since: 3.0
Located at Web/THttpRequest.php
Methods summary
public string
# getID( )

Returns

string
id of this module

Implementation of

IModule::getID()
public
# setID( string $value )

Parameters

$value
string
id of this module

Implementation of

IModule::setID()
public
# init( TXmlElement $config )

Initializes the module. This method is required by IModule and is invoked by application.

Initializes the module. This method is required by IModule and is invoked by application.

Parameters

$config
TXmlElement
module configuration

Implementation of

IModule::init()
public mixed
# stripSlashes( mixed & $data )

Strips slashes from input data. This method is applied when magic quotes is enabled.

Strips slashes from input data. This method is applied when magic quotes is enabled.

Parameters

$data
mixed
input data to be processed

Returns

mixed
processed data
public TUri
# getUrl( )

Returns

TUri
the request URL
public
# setEnableCache( boolean $value )

Set true to cache the UrlManager instance. Consider to enable this cache when the application defines a lot of TUrlMappingPatterns

Set true to cache the UrlManager instance. Consider to enable this cache when the application defines a lot of TUrlMappingPatterns

Parameters

$value
boolean
true to cache urlmanager instance.
public boolean
# getEnableCache( )

Returns

boolean
true if urlmanager instance should be cached, false otherwise.
protected
# getCacheKey( )
protected boolean
# cacheUrlManager( mixed $manager )

Saves the current UrlManager instance to cache.

Saves the current UrlManager instance to cache.

Returns

boolean
true if UrlManager instance was cached, false otherwise.
protected TUrlManager
# loadCachedUrlManager( )

Loads UrlManager instance from cache.

Loads UrlManager instance from cache.

Returns

TUrlManager
intance if load was successful, null otherwise.
public string
# getUrlManager( )

Returns

string
the ID of the URL manager module
public
# setUrlManager( string $value )

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.

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.

Parameters

$value
string
the ID of the URL manager module
public TUrlManager
# getUrlManagerModule( )

Returns

TUrlManager
the URL manager module
public THttpRequestUrlFormat
# getUrlFormat( )

Returns

THttpRequestUrlFormat
the format of URLs. Defaults to THttpRequestUrlFormat::Get.
public
# setUrlFormat( THttpRequestUrlFormat $value )

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 THttpRequest::constructUrl() and how GET variables are parsed.

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 THttpRequest::constructUrl() and how GET variables are parsed.

Parameters

$value
THttpRequestUrlFormat
the format of URLs.
public string
# getUrlParamSeparator( )

Returns

string
separator used to separate GET variable name and value when URL format is Path. Defaults to comma ','.
public
# setUrlParamSeparator( string $value )

Parameters

$value
string
separator used to separate GET variable name and value when URL format is Path.

Throws

TInvalidDataValueException
if the separator is not a single character
public string
# getRequestType( )

Returns

string
request type, can be GET, POST, HEAD, or PUT
public string
# getContentType( boolean $mimetypeOnly = true )

Parameters

$mimetypeOnly
boolean
$mimetypeOnly whether to return only the mimetype (default: true)

Returns

string
content type (e.g. 'application/json' or 'text/html; encoding=gzip') or null if not specified
public boolean
# getIsSecureConnection( )

Returns

boolean
if the request is sent via secure channel (https)
public string
# getPathInfo( )

Returns

string
part of the request URL after script name and before question mark.
public string
# getQueryString( )

Returns

string
part of that request URL after the question mark
public string
# getHttpProtocolVersion( )

Returns

string
the requested http procolol. Blank string if not defined.
public array
# getHeaders( integer|null $case = null )

Parameters

$case
integer|null
Either CASE_UPPER or CASE_LOWER or as is null (default)

Returns

array
public string
# getRequestUri( )

Returns

string
part of that request URL after the host info (including pathinfo and query string)
public string
# getBaseUrl( boolean|null $forceSecureConnection = null )

Parameters

$forceSecureConnection
boolean|null
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

Returns

string
schema and hostname of the requested URL
public string
# getApplicationUrl( )

Returns

string
entry script URL (w/o host part)
public string
# getAbsoluteApplicationUrl( boolean|null $forceSecureConnection = null )

Parameters

$forceSecureConnection
boolean|null
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

Returns

string
entry script URL (w/ host part)
public string
# getApplicationFilePath( )

Returns

string
application entry script file path (processed w/ realpath())
public string
# getServerName( )

Returns

string
server name
public integer
# getServerPort( )

Returns

integer
server port number
public string
# getUrlReferrer( )

Returns

string
URL referrer, null if not present
public array
# getBrowser( )

Returns

array
user browser capabilities

See

get_browser
public string
# getUserAgent( )

Returns

string
user agent
public string
# getUserHostAddress( )

Returns

string
user IP address
public string
# getUserHost( )

Returns

string
user host name, null if cannot be determined
public string
# getAcceptTypes( )

Returns

string
user browser accept types
public array
# getUserLanguages( )

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.

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.

Returns

array
list of user preferred languages.
public boolean
# getEnableCookieValidation( )

Returns

boolean
whether cookies should be validated. Defaults to false.
public
# setEnableCookieValidation( boolean $value )

Parameters

$value
boolean
whether cookies should be validated.
public integer
# getCgiFix( )

Returns

integer
whether to use ORIG_PATH_INFO and/or ORIG_SCRIPT_NAME. Defaults to 0.

See

THttpRequest::CGIFIX__PATH_INFO, THttpRequest::CGIFIX__SCRIPT_NAME
public
# setCgiFix( integer $value )

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!

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!

Parameters

$value
integer
enable bitwise to use ORIG_PATH_INFO and/or ORIG_SCRIPT_NAME.

See

THttpRequest::CGIFIX__PATH_INFO, THttpRequest::CGIFIX__SCRIPT_NAME
public THttpCookieCollection
# getCookies( )

Returns

THttpCookieCollection
list of cookies to be sent
public array
# getUploadedFiles( )

Returns

array
list of uploaded files.
public array
# getServerVariables( )

Returns

array
list of server variables.
public array
# getEnvironmentVariables( )

Returns

array
list of environment variables.
public string
# constructUrl( string $serviceID, string $serviceParam, array $getItems = null, boolean $encodeAmpersand = true, boolean $encodeGetItems = true )

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 setUrlManager UrlManager to provide your own URL scheme.

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 setUrlManager 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 getBaseUrl BaseUrl.

Parameters

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

Returns

string
URL

See

TUrlManager::constructUrl()
protected array
# parseUrl( )

Parses the request URL and returns an array of input parameters (excluding GET variables). You may override this method to support customized URL format.

Parses the request URL and returns an array of input parameters (excluding GET variables). You may override this method to support customized URL format.

Returns

array
list of input parameters, indexed by parameter names

See

TUrlManager::parseUrl()
public string
# resolveRequest( array $serviceIDs )

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.

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.

Parameters

$serviceIDs
array
list of valid service IDs

Returns

string
the currently requested service ID, null if no service ID is found

See

THttpRequest::constructUrl()
public boolean
# getRequestResolved( )

Returns

boolean
true if request is already resolved, false otherwise.
public string
# getServiceID( )

Returns

string
requested service ID
public
# setServiceID( string $value )

Sets the requested service ID.

Sets the requested service ID.

Parameters

$value
string
requested service ID
public string
# getServiceParameter( )

Returns

string
requested service parameter
public
# setServiceParameter( string $value )

Sets the requested service parameter.

Sets the requested service parameter.

Parameters

$value
string
requested service parameter
public Iterator
# getIterator( )

Returns an iterator for traversing the items in the list. This method is required by the interface IteratorAggregate.

Returns an iterator for traversing the items in the list. This method is required by the interface IteratorAggregate.

Returns

Iterator
an iterator for traversing the items in the list.

Implementation of

IteratorAggregate::getIterator()
public integer
# getCount( )

Returns

integer
the number of items in the request
public integer
# count( )

Returns the number of items in the request. This method is required by Countable interface.

Returns the number of items in the request. This method is required by Countable interface.

Returns

integer
number of items in the request.

Implementation of

Countable::count()
public array
# getKeys( )

Returns

array
the key list
public mixed
# itemAt( mixed $key )

Returns the item with the specified key. This method is exactly the same as THttpRequest::offsetGet().

Returns the item with the specified key. This method is exactly the same as THttpRequest::offsetGet().

Parameters

$key
mixed
the key

Returns

mixed
the element at the offset, null if no element is found at the offset
public
# add( mixed $key, mixed $value )

Adds an item into the request. Note, if the specified key already exists, the old value will be overwritten.

Adds an item into the request. Note, if the specified key already exists, the old value will be overwritten.

Parameters

$key
mixed
key
$value
mixed
value
public mixed
# remove( mixed $key )

Removes an item from the request by its key.

Removes an item from the request by its key.

Parameters

$key
mixed
the key of the item to be removed

Returns

mixed
the removed value, null if no such key exists.

Throws

TInvalidOperationException
if the item cannot be removed
public
# clear( )

Removes all items in the request.

Removes all items in the request.

public boolean
# contains( mixed $key )

Parameters

$key
mixed
the key

Returns

boolean
whether the request contains an item with the specified key
public array
# toArray( )

Returns

array
the list of items in array
public boolean
# offsetExists( mixed $offset )

Returns whether there is an element at the specified offset. This method is required by the interface ArrayAccess.

Returns whether there is an element at the specified offset. This method is required by the interface ArrayAccess.

Parameters

$offset
mixed
the offset to check on

Returns

boolean

Implementation of

ArrayAccess::offsetExists()
public mixed
# offsetGet( integer $offset )

Returns the element at the specified offset. This method is required by the interface ArrayAccess.

Returns the element at the specified offset. This method is required by the interface ArrayAccess.

Parameters

$offset
integer
the offset to retrieve element.

Returns

mixed
the element at the offset, null if no element is found at the offset

Implementation of

ArrayAccess::offsetGet()
public
# offsetSet( integer $offset, mixed $item )

Sets the element at the specified offset. This method is required by the interface ArrayAccess.

Sets the element at the specified offset. This method is required by the interface ArrayAccess.

Parameters

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

Implementation of

ArrayAccess::offsetSet()
public
# offsetUnset( mixed $offset )

Unsets the element at the specified offset. This method is required by the interface ArrayAccess.

Unsets the element at the specified offset. This method is required by the interface ArrayAccess.

Parameters

$offset
mixed
the offset to unset element

Implementation of

ArrayAccess::offsetUnset()
Methods inherited from TApplicationComponent
getApplication(), getRequest(), getResponse(), getService(), getSession(), getUser(), publishAsset(), publishFilePath()
Methods inherited from TComponent
__call(), __construct(), __destruct(), __get(), __isset(), __set(), __sleep(), __unset(), __wakeup(), addParsedObject(), asa(), attachBehavior(), attachBehaviors(), attachClassBehavior(), attachEventHandler(), canGetProperty(), canSetProperty(), clearBehaviors(), createdOnTemplate(), detachBehavior(), detachBehaviors(), detachClassBehavior(), detachEventHandler(), disableBehavior(), disableBehaviors(), enableBehavior(), enableBehaviors(), evaluateExpression(), evaluateStatements(), fxAttachClassBehavior(), fxDetachClassBehavior(), getAutoGlobalListen(), getBehaviorsEnabled(), getClassHierarchy(), getEventHandlers(), getListeningToGlobalEvents(), getSubProperty(), hasEvent(), hasEventHandler(), hasProperty(), isa(), listen(), raiseEvent(), setSubProperty(), unlisten()
Constants summary
integer CGIFIX__PATH_INFO 1
#
integer CGIFIX__SCRIPT_NAME 2
#
Constants inherited from TComponent
GLOBAL_RAISE_EVENT_LISTENER
Terms of Service | Contact Us
PRADO v3.2.4 API Manual API documentation generated by ApiGen 2.8.0
Copyright © 2006-2014 by the PRADO Group.
Powered by PRADO