Class NHttpRequest


NHttpRequest provides access scheme for request sent via HTTP.

NObject
   |
   --NHttpRequest

Implements interfaces:

Author: David Grudl
Copyright: Copyright (c) 2004, 2009 David Grudl
Located: in /Web/HttpRequest.php (line 49)
Public Method Summary
void
addUriFilter (string $pattern, [string $replacement = ''], [int $component = NULL])
Sets request URI filter.
string
detectLanguage ($langs)
Parse Accept-Language header and returns prefered language.
mixed
getCookie (string $key, [mixed $default = NULL])
Returns variable provided to the script via HTTP cookies.
array
Returns variables provided to the script via HTTP cookies.
NHttpUploadedFile
getFile (string $key)
Returns uploaded file.
array
Returns uploaded files.
mixed
getHeader (string $header, [mixed $default = NULL])
Return the value of the HTTP header. Pass the header name as the plain, HTTP-specified header name (e.g. 'Accept-Encoding').
array
Returns all HTTP headers.
string
Returns HTTP request method (GET, POST, HEAD, PUT, ...). The method is case-sensitive.
NUri
Returns URL object.
mixed
getPost ([string $key = NULL], [mixed $default = NULL])
Returns variable provided to the script via POST method ($_POST).
string
Returns HTTP POST data in raw format (only for "application/x-www-form-urlencoded").
mixed
getQuery ([string $key = NULL], [mixed $default = NULL])
Returns variable provided to the script via URL query ($_GET).
NUri|NULL
Returns referrer.
string
Returns the IP address of the remote client.
string
Returns the host of the remote client.
NUriScript
getUri ()
Returns URL object.
array
Returns request URI filter.
void
Initializes $this->query, $this->files, $this->cookies and $this->files arrays
bool
isAjax ()
Is AJAX request?
bool
isMethod (string $method)
Checks if the request method is the given one.
bool
isPost ()
Checks if the request method is POST.
bool
Is the request is sent via secure channel (https).
NHttpRequest
setEncoding (array $encoding, string 1)
Recursively converts and checks encoding.
NHttpRequest
setUri (NUriScript $uri)
Sets URL object.
Protected Method Summary
protected void
Detects uri, base path and script path of the request.
Methods Inherited From NObject
extensionMethod(), getClass(), getReflection(), __call(), __callStatic(), __get(), __isset(), __set(), __unset()
Variable Summary
protected array $cookies

line 61

protected string $encoding

line 79

protected array $files

line 58

protected array $headers

line 70

NHttpRequest::getHeaders()
protected NUri $originalUri

line 67

NHttpRequest::getOriginalUri()
protected array $post

line 55

protected array $query

line 52

protected NUriScript $uri

line 64

NHttpRequest::getUri()
protected array $uriFilter array( PHP_URL_PATH => array('#/{2,}#' => '/'),// '%20' => '' 0=>array(),//...

line 73


Method Details

line 138

addUriFilter

public void addUriFilter (string $pattern, [string $replacement = ''], [int $component = NULL])

Sets request URI filter.

Input
string $pattern pattern to search for
string $replacement string to replace
int $component PHP_URL_PATH or NULL
Output
void  

line 692

detectLanguage

public string detectLanguage ($langs)

Parse Accept-Language header and returns prefered language.

Input
$langs Supported languages
Output
string  

line 168

detectUri

protected void detectUri ()

Detects uri, base path and script path of the request.

Output
void  

line 383

getCookie

public mixed getCookie (string $key, [mixed $default = NULL])

Returns variable provided to the script via HTTP cookies.

Implementation of:

Input
string $key key
mixed $default default value
Output
mixed  

line 406

getCookies

public array getCookies ()

Returns variables provided to the script via HTTP cookies.

Implementation of:

Output
array  

line 351

getFile

public NHttpUploadedFile getFile (string $key)

Returns uploaded file.

Implementation of:

Input
string $key key (or more keys)
Output
NHttpUploadedFile  

line 366

getFiles

public array getFiles ()

Returns uploaded files.

Implementation of:

Output
array  

line 587

getHeader

public mixed getHeader (string $header, [mixed $default = NULL])

Return the value of the HTTP header. Pass the header name as the plain, HTTP-specified header name (e.g. 'Accept-Encoding').

Implementation of:

Input
string $header
mixed $default
Output
mixed  

line 604

getHeaders

public array getHeaders ()

Returns all HTTP headers.

Implementation of:

Output
array  

line 550

getMethod

public string getMethod ()

Returns HTTP request method (GET, POST, HEAD, PUT, ...). The method is case-sensitive.

Implementation of:

Output
string  

line 121

getOriginalUri

public NUri getOriginalUri ()

Returns URL object.

Output
NUri  

line 316

getPost

public mixed getPost ([string $key = NULL], [mixed $default = NULL])

Returns variable provided to the script via POST method ($_POST).

If no key is passed, returns the entire array.

Implementation of:

Input
string $key key
mixed $default default value
Output
mixed  

line 339

getPostRaw

public string getPostRaw ()

Returns HTTP POST data in raw format (only for "application/x-www-form-urlencoded").

Implementation of:

Output
string  

line 290

getQuery

public mixed getQuery ([string $key = NULL], [mixed $default = NULL])

Returns variable provided to the script via URL query ($_GET).

If no key is passed, returns the entire array.

Implementation of:

Input
string $key key
mixed $default default value
Output
mixed  

line 628

getReferer

public NUri|NULL getReferer ()

Returns referrer.

Output
NUri|NULL  

line 662

getRemoteAddress

public string getRemoteAddress ()

Returns the IP address of the remote client.

Output
string  

line 673

getRemoteHost

public string getRemoteHost ()

Returns the host of the remote client.

Implementation of:

Output
string  

line 91

getUri

public NUriScript getUri ()

Returns URL object.

Implementation of:

Output
NUriScript  

line 157

getUriFilters

public array getUriFilters ()

Returns request URI filter.

Output
array  

line 438

initialize

public void initialize ()

Initializes $this->query, $this->files, $this->cookies and $this->files arrays

Output
void  

line 651

isAjax

public bool isAjax ()

Is AJAX request?

Implementation of:

Output
bool  

line 562

isMethod

public bool isMethod (string $method)

Checks if the request method is the given one.

Implementation of:

Input
string $method
Output
bool  

line 573

isPost

public bool isPost ()

Checks if the request method is POST.

Output
bool  

line 640

isSecured

public bool isSecured ()

Is the request is sent via secure channel (https).

Implementation of:

Output
bool  

line 423

setEncoding

public NHttpRequest setEncoding (array $encoding, string 1)

Recursively converts and checks encoding.

Input
array $encoding
string 1
Output
NHttpRequest provides a fluent interface

line 106

setUri

public NHttpRequest setUri (NUriScript $uri)

Sets URL object.

Input
NUriScript $uri
Output
NHttpRequest provides a fluent interface