class Request
Request represents an HTTP request.
Properties
| ParameterBag | $attributes | |
| ParameterBag | $request | |
| ParameterBag | $query | |
| ServerBag | $server | |
| FileBag | $files | |
| ParameterBag | $cookies | |
| HeaderBag | $headers |
Methods
|
__construct(array $query = array(), array $request = array(), array $attributes = array(), array $cookies = array(), array $files = array(), array $server = array(), string $content = null)
Constructor. |
||
|
initialize(array $query = array(), array $request = array(), array $attributes = array(), array $cookies = array(), array $files = array(), array $server = array(), string $content = null)
Sets the parameters for this request. |
||
| static Request |
createFromGlobals()
Creates a new request with values from PHP's super globals. |
|
| static Request |
create(string $uri, string $method = 'GET', array $parameters = array(), array $cookies = array(), array $files = array(), array $server = array(), string $content = null)
Creates a Request based on a given URI and configuration. |
|
|
duplicate(array $query = null, array $request = null, array $attributes = null, array $cookies = null, array $files = null, array $server = null)
Clones a request and overrides some of its parameters. |
||
|
__clone()
Clones the current request. |
||
| string |
__toString()
Returns the request as a string. |
|
|
overrideGlobals()
Overrides the PHP global variables according to this request instance. |
||
| static |
trustProxyData()
Trusts $_SERVER entries coming from proxies. |
|
| mixed |
get(string $key, mixed $default = null, type $deep = false)
Gets a "parameter" value. |
|
| Session|null |
getSession()
Gets the Session. |
|
| boolean |
hasPreviousSession()
Whether the request contains a Session which was started in one of the previous requests. |
|
| boolean |
hasSession()
Whether the request contains a Session object. |
|
|
setSession(Session $session)
Sets the Session. |
||
| string |
getClientIp(Boolean $proxy = false)
Returns the client IP address. |
|
| string |
getScriptName()
Returns current script name. |
|
| string |
getPathInfo()
Returns the path being requested relative to the executed script. |
|
| string |
getBasePath()
Returns the root path from which this request is executed. |
|
| string |
getBaseUrl()
Returns the root url from which this request is executed. |
|
| string |
getScheme()
Gets the request's scheme. |
|
| string |
getPort()
Returns the port on which the request is made. |
|
| string |
getHttpHost()
Returns the HTTP host being requested. |
|
| string |
getRequestUri()
Returns the requested URI. |
|
| string |
getUri()
Generates a normalized URI for the Request. |
|
| string |
getUriForPath(string $path)
Generates a normalized URI for the given path. |
|
| string|null |
getQueryString()
Generates the normalized query string for the Request. |
|
| Boolean |
isSecure()
Checks whether the request is secure or not. |
|
| string |
getHost()
Returns the host name. |
|
|
setMethod(string $method)
Sets the request method. |
||
| string |
getMethod()
Gets the request method. |
|
| string |
getMimeType(string $format)
Gets the mime type associated with the format. |
|
| string |
getFormat(string $mimeType)
Gets the format associated with the mime type. |
|
|
setFormat(string $format, string|array $mimeTypes)
Associates a format with mime types. |
||
| string |
getRequestFormat(string $default = 'html')
Gets the request format. |
|
|
setRequestFormat(string $format)
Sets the request format. |
||
| setLocale($locale) | ||
| getLocale() | ||
| Boolean |
isMethodSafe()
Checks whether the method is safe or not. |
|
| string|resource |
getContent(Boolean $asResource = false)
Returns the request body content. |
|
| array |
getETags()
Gets the Etags. |
|
| isNoCache() | ||
| string|null |
getPreferredLanguage(array $locales = null)
Returns the preferred language. |
|
| array |
getLanguages()
Gets a list of languages acceptable by the client browser. |
|
| array |
getCharsets()
Gets a list of charsets acceptable by the client browser. |
|
| array |
getAcceptableContentTypes()
Gets a list of content types acceptable by the client browser |
|
| Boolean |
isXmlHttpRequest()
Returns true if the request is a XMLHttpRequest. |
|
| array |
splitHttpAcceptHeader(string $header)
Splits an Accept-* HTTP header. |
Details
at line 101
public
__construct(array $query = array(), array $request = array(), array $attributes = array(), array $cookies = array(), array $files = array(), array $server = array(), string $content = null)
Constructor.
at line 121
public
initialize(array $query = array(), array $request = array(), array $attributes = array(), array $cookies = array(), array $files = array(), array $server = array(), string $content = null)
Sets the parameters for this request.
This method also re-initializes all properties.
at line 150
static public Request
createFromGlobals()
Creates a new request with values from PHP's super globals.
at line 179
static public Request
create(string $uri, string $method = 'GET', array $parameters = array(), array $cookies = array(), array $files = array(), array $server = array(), string $content = null)
Creates a Request based on a given URI and configuration.
at line 263
public
duplicate(array $query = null, array $request = null, array $attributes = null, array $cookies = null, array $files = null, array $server = null)
Clones a request and overrides some of its parameters.
at line 304
public
__clone()
Clones the current request.
Note that the session is not cloned as duplicated requests
are most of the time sub-requests of the main one.
at line 320
public string
__toString()
Returns the request as a string.
at line 335
public
overrideGlobals()
Overrides the PHP global variables according to this request instance.
It overrides $_GET, $_POST, $_REQUEST, $_SERVER, $_COOKIE, and $_FILES.
at line 365
static public
trustProxyData()
Trusts $_SERVER entries coming from proxies.
You should only call this method if your application
is hosted behind a reverse proxy that you manage.
at line 386
public mixed
get(string $key, mixed $default = null, type $deep = false)
Gets a "parameter" value.
This method is mainly useful for libraries that want to provide some flexibility.
Order of precedence: GET, PATH, POST, COOKIE
Avoid using this method in controllers:
* slow
* prefer to get from a "named" source
at line 398
public Session|null
getSession()
Gets the Session.
at line 411
public boolean
hasPreviousSession()
Whether the request contains a Session which was started in one of the previous requests.
at line 424
public boolean
hasSession()
Whether the request contains a Session object.
at line 436
public
setSession(Session $session)
Sets the Session.
at line 450
public string
getClientIp(Boolean $proxy = false)
Returns the client IP address.
at line 472
public string
getScriptName()
Returns current script name.
at line 492
public string
getPathInfo()
Returns the path being requested relative to the executed script.
The path info always starts with a /.
Suppose this request is instantiated from /mysite on localhost:
* http://localhost/mysite returns an empty string
* http://localhost/mysite/about returns '/about'
* http://localhost/mysite/about?var=1 returns '/about'
at line 514
public string
getBasePath()
Returns the root path from which this request is executed.
Suppose that an index.php file instantiates this request object:
* http://localhost/index.php returns an empty string
* http://localhost/index.php/page returns an empty string
* http://localhost/web/index.php return '/web'
at line 535
public string
getBaseUrl()
Returns the root url from which this request is executed.
The base URL never ends with a /.
This is similar to getBasePath(), except that it also includes the
script filename (e.g. index.php) if one exists.
at line 551
public string
getScheme()
Gets the request's scheme.
at line 563
public string
getPort()
Returns the port on which the request is made.
at line 581
public string
getHttpHost()
Returns the HTTP host being requested.
The port name will be appended to the host if it's non-standard.
at line 600
public string
getRequestUri()
Returns the requested URI.
at line 618
public string
getUri()
Generates a normalized URI for the Request.
at line 637
public string
getUriForPath(string $path)
Generates a normalized URI for the given path.
at line 652
public string|null
getQueryString()
Generates the normalized query string for the Request.
It builds a normalized query string, where keys/value pairs are alphabetized
and have consistent escaping.
at line 683
public Boolean
isSecure()
Checks whether the request is secure or not.
at line 701
public string
getHost()
Returns the host name.
at line 728
public
setMethod(string $method)
Sets the request method.
at line 743
public string
getMethod()
Gets the request method.
The method is always an uppercased string.
at line 764
public string
getMimeType(string $format)
Gets the mime type associated with the format.
at line 782
public string
getFormat(string $mimeType)
Gets the format associated with the mime type.
at line 809
public
setFormat(string $format, string|array $mimeTypes)
Associates a format with mime types.
at line 833
public string
getRequestFormat(string $default = 'html')
Gets the request format.
Here is the process to determine the format:
* format defined by the user (with setRequestFormat())
* _format request parameter
* $default
at line 849
public
setRequestFormat(string $format)
Sets the request format.
at line 854
public
setLocale($locale)
at line 863
public
getLocale()
at line 879
public Boolean
isMethodSafe()
Checks whether the method is safe or not.
at line 891
public string|resource
getContent(Boolean $asResource = false)
Returns the request body content.
at line 915
public array
getETags()
Gets the Etags.
at line 920
public
isNoCache()
at line 934
public string|null
getPreferredLanguage(array $locales = null)
Returns the preferred language.
at line 958
public array
getLanguages()
Gets a list of languages acceptable by the client browser.
at line 1000
public array
getCharsets()
Gets a list of charsets acceptable by the client browser.
at line 1016
public array
getAcceptableContentTypes()
Gets a list of content types acceptable by the client browser
at line 1035
public Boolean
isXmlHttpRequest()
Returns true if the request is a XMLHttpRequest.
It works if your JavaScript library set an X-Requested-With HTTP header.
It is known to work with Prototype, Mootools, jQuery.
at line 1047
public array
splitHttpAcceptHeader(string $header)
Splits an Accept-* HTTP header.