.

RequestInfo Class Reference
[Lib]

Class that returns informations about current request. More...

List of all members.

Public Member Functions

  __construct ($server_array)
  is_console ()
  Returns true, if current request was done form command line.
  is_ssl ()
  Returns true, if request was done using HTTPS.
  method ()
  Returns request method (GET, POST, PUT, DELETE, HEAD etc.
  remote_address ()
  Client IP Address.
  remote_host ()
  Client Host, if resolvable.
  url_invoked ($type=self::ABSOLUTE)
  Returns the URL invokes as a string, either absolute or relative.
  user_agent ()
  Returns user agent.

Static Public Member Functions

static  create ($data_array)
  Create instance of RequestInfo.
static  current ()
  Returns info about current request.

Public Attributes

const  ABSOLUTE = 'absolute'
const  RELATIVE = 'relative'

Protected Member Functions

  compute_cl_invoked ($type)
  Computes commadn line invoked.
  compute_url_invoked ($type)
  Computes URL invokes.

Protected Attributes

  $data = array()

Detailed Description

Class that returns informations about current request.

Author:
Gerd Riesselmann

Definition at line 8 of file requestinfo.cls.php.


Constructor & Destructor Documentation

RequestInfo::__construct ( server_array  ) 

Definition at line 20 of file requestinfo.cls.php.

00020                                                    {
00021                 $this->data = $server_array;    
00022         }

Member Function Documentation

RequestInfo::compute_cl_invoked ( type  )  [protected]

Computes commadn line invoked.

Parameters:
string  $type
Returns:
string

Definition at line 132 of file requestinfo.cls.php.

00132                                                      {
00133                 $ret = 'http://local/php ';
00134                 $ret .= implode(' ', Arr::get_item($_SERVER, 'argv', array()));
00135                 return $ret;                            
00136         }
RequestInfo::compute_url_invoked ( type  )  [protected]

Computes URL invokes.

Parameters:
string  $type
Returns:
string

Definition at line 93 of file requestinfo.cls.php.

00093                                                       {
00094                 $ret = '';
00095                 // This is the original URL passed to IIS 
00096                 // http://martin.bz.it/post/2008/03/Url-Rewriting-PHP-und-IIS.aspx
00097                 $ret .= Arr::get_item($this->data, 'HTTP_X_REWRITE_URL', '');
00098                 if ($ret === '') {
00099                         // This is the original URL, passed to apache
00100                         $ret .= Arr::get_item($this->data, 'REQUEST_URI', '');
00101                 }
00102                 if ($ret === '') {
00103                         // No rewriting, no request uri, build URL by hand 
00104                         $ret .= Arr::get_item($this->data, 'SCRIPT_NAME', '');
00105                         if ($ret === '') {
00106                                 $ret .= Arr::get_item($this->data, 'PHP_SELF', '');
00107                         }
00108                         $query = Arr::get_item($this->data, 'QUERY_STRING', '');
00109                 if ($query !== '') {
00110                         $ret .= '?' . $query;
00111                         }
00112                 }               
00113                 if ($type == self::ABSOLUTE) {
00114                         $prefix = $this->is_ssl() ? 'https://' : 'http://';
00115                         // Check proxy forwarded stuff
00116                         $prefix .= Arr::get_item(
00117                                 $_SERVER, 'HTTP_X_FORWARDED_HOST', Arr::get_item(
00118                                         $_SERVER, 'HTTP_HOST', Config::get_value(Config::URL_DOMAIN)
00119                                 )
00120                         );
00121                         $ret = $prefix . $ret;
00122                 }
00123                 return $ret;
00124         }
static RequestInfo::create ( data_array  )  [static]

Create instance of RequestInfo.

Parameters:
array  $data_array Array that follows rules for $_SERVER
Returns:
RequestInfo

Definition at line 42 of file requestinfo.cls.php.

00042                                                    {
00043                 return new RequestInfo($data_array);
00044         }
static RequestInfo::current (  )  [static]

Returns info about current request.

Returns:
RequestInfo

Definition at line 29 of file requestinfo.cls.php.

00029                                          {
00030                 if (self::$_current === null) {
00031                         self::$_current = new RequestInfo($_SERVER);
00032                 }
00033                 return clone(self::$_current);
00034         }
RequestInfo::is_console (  ) 

Returns true, if current request was done form command line.

Returns:
bool

Definition at line 66 of file requestinfo.cls.php.

00066                                      {
00067                 $protocol = Arr::get_item($_SERVER, 'SERVER_PROTOCOL', false);
00068                 return empty($protocol);                 
00069         }
RequestInfo::is_ssl (  ) 

Returns true, if request was done using HTTPS.

Returns:
bool

Definition at line 51 of file requestinfo.cls.php.

00051                                  {
00052                 $https = Arr::get_item($this->data, 'HTTPS', false);
00053                 if ($https === false) {
00054                         // Not set, e.g. by nginx
00055                         return (Arr::get_item($this->data, 'SERVER_PORT', '') == '443');
00056                 } else {
00057                         return $https != 'off';
00058                 }
00059         }
RequestInfo::method (  ) 

Returns request method (GET, POST, PUT, DELETE, HEAD etc.

)

Returns:
string

Definition at line 143 of file requestinfo.cls.php.

00143                                  {
00144                 return strtoupper(Arr::get_item($this->data, 'REQUEST_METHOD', 'GET'));
00145         }
RequestInfo::remote_address (  ) 

Client IP Address.

Returns:
string

Definition at line 152 of file requestinfo.cls.php.

00152                                          {
00153                 $ret = '';
00154                 // Check for X-Forwarded-For use REMOTE_ADDR as fallback
00155                 $in = Arr::get_item($this->data, 'HTTP_X_FORWARDED_FOR', Arr::get_item($this->data, 'REMOTE_ADDR', ''));
00156                 if ($in) {
00157                         // May be comma separeted list (in case of proxies involved)
00158                         $arr_ips = explode(',', $in);
00159                         foreach($arr_ips as $ip) {
00160                                 if (Validation::is_ip($ip)) {
00161                                         $ret = $ip;
00162                                         break;
00163                                 }
00164                         }
00165                 }
00166                 return $ret;
00167         }
RequestInfo::remote_host (  ) 

Client Host, if resolvable.

If not, remote IP is returned

Returns:
string

Definition at line 174 of file requestinfo.cls.php.

00174                                       {
00175                 $ret = '';
00176                 if (!isset($this->data['HTTP_X_FORWARDED_FOR'])) {
00177                         $ret = Arr::get_item($this->data, 'REMOTE_HOST', '');
00178                 }
00179                 if ($ret === '') {
00180                         $ret = $this->remote_address();
00181                         if ($ret) {
00182                                 $ret = @gethostbyaddr($ret);
00183                         }
00184                 }
00185                 return $ret;
00186         }
RequestInfo::url_invoked ( type = self::ABSOLUTE  ) 

Returns the URL invokes as a string, either absolute or relative.

Parameters:
string  $type

Definition at line 76 of file requestinfo.cls.php.

00076                                                           {
00077                 $ret = '';
00078                 if ($this->is_console()) {
00079                         $ret = $this->compute_cl_invoked($type);
00080                 }
00081                 else {
00082                         $ret = $this->compute_url_invoked($type);
00083                 }
00084                 return $ret;
00085         }
RequestInfo::user_agent (  ) 

Returns user agent.

Returns:
string

Definition at line 193 of file requestinfo.cls.php.

00193                                      {
00194                 return Arr::get_item($this->data, 'HTTP_USER_AGENT', '');               
00195         }

Member Data Documentation

RequestInfo::$data = array() [protected]

Definition at line 18 of file requestinfo.cls.php.

const RequestInfo::ABSOLUTE = 'absolute'

Definition at line 9 of file requestinfo.cls.php.

const RequestInfo::RELATIVE = 'relative'

Definition at line 10 of file requestinfo.cls.php.


The documentation for this class was generated from the following file: