Methods summary
public
|
#
__construct( array $query = array(), array $request = array(), array $attributes = array(), array $cookies = array(), array $files = array(), array $server = array(), string $content = null )
Constructor.
Parameters
- $query
array $query The GET parameters
- $request
array $request The POST parameters
- $attributes
array $attributes The request attributes (parameters parsed from the PATH_INFO, ...)
- $cookies
array $cookies The COOKIE parameters
- $files
array $files The FILES parameters
- $server
array $server The SERVER parameters
- $content
string $content The raw body data
Api
|
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.
Sets the parameters for this request.
This method also re-initializes all properties.
Parameters
- $query
array $query The GET parameters
- $request
array $request The POST parameters
- $attributes
array $attributes The request attributes (parameters parsed from the PATH_INFO, ...)
- $cookies
array $cookies The COOKIE parameters
- $files
array $files The FILES parameters
- $server
array $server The SERVER parameters
- $content
string $content The raw body data
Api
|
public static
Symfony\Component\HttpFoundation\Request
|
#
createFromGlobals( )
Creates a new request with values from PHP's super globals.
Creates a new request with values from PHP's super globals.
Returns
Api
|
public static
Symfony\Component\HttpFoundation\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.
Creates a Request based on a given URI and configuration.
The information contained in the URI always take precedence over the other
information (server and parameters).
Parameters
- $uri
string $uri The URI
- $method
string $method The HTTP method
- $parameters
array $parameters The query (GET) or request (POST) parameters
- $cookies
array $cookies The request cookies ($_COOKIE)
- $files
array $files The request files ($_FILES)
- $server
array $server The server parameters ($_SERVER)
- $content
string $content The raw body data
Returns
Api
|
public
Symfony\Component\HttpFoundation\Request
|
#
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.
Clones a request and overrides some of its parameters.
Parameters
- $query
array $query The GET parameters
- $request
array $request The POST parameters
- $attributes
array $attributes The request attributes (parameters parsed from the PATH_INFO, ...)
- $cookies
array $cookies The COOKIE parameters
- $files
array $files The FILES parameters
- $server
array $server The SERVER parameters
Returns
Api
|
public
|
#
__clone( )
Clones the current request.
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.
|
public
string
|
#
__toString( )
Returns the request as a string.
Returns the request as a string.
Returns
string The request
|
public
|
#
overrideGlobals( )
Overrides the PHP global variables according to this request instance.
Overrides the PHP global variables according to this request instance.
It overrides $_GET, $_POST, $_REQUEST, $_SERVER, $_COOKIE. $_FILES is never
override, see rfc1867
Api
|
public static
|
#
trustProxyData( )
Trusts $_SERVER entries coming from proxies.
Trusts $_SERVER entries coming from proxies.
Deprecated
Deprecated since version 2.0, to be removed in 2.3. Use setTrustedProxies
instead.
|
public static
|
#
setTrustedProxies( array $proxies )
Sets a list of trusted proxies.
Sets a list of trusted proxies.
You should only list the reverse proxies that you manage directly.
Parameters
- $proxies
array $proxies A list of trusted proxies
Api
|
public static
array
|
#
getTrustedProxies( )
Gets the list of trusted proxies.
Gets the list of trusted proxies.
Returns
array An array of trusted proxies.
|
public static
boolean
|
#
isProxyTrusted( )
Returns true if $_SERVER entries coming from proxies are trusted, false
otherwise.
Returns true if $_SERVER entries coming from proxies are trusted, false
otherwise.
Deprecated
Deprecated since version 2.2, to be removed in 2.3. Use getTrustedProxies
instead.
Returns
boolean
|
public static
string
|
#
normalizeQueryString( string $qs )
Normalizes a query string.
Normalizes a query string.
It builds a normalized query string, where keys/value pairs are alphabetized,
have consistent escaping and unneeded delimiters are removed.
Parameters
- $qs
string $qs Query string
Returns
string A normalized query string for the Request
|
public static
|
#
enableHttpMethodParameterOverride( )
Enables support for the _method request parameter to determine the intended
HTTP method.
Enables support for the _method request parameter to determine the intended
HTTP method.
Be warned that enabling this feature might lead to CSRF issues in your code.
Check that you are using CSRF tokens when required.
The HTTP method can only be overridden when the real HTTP method is POST.
|
public static
Boolean
|
#
getHttpMethodParameterOverride( )
Checks whether support for the _method request parameter is enabled.
Checks whether support for the _method request parameter is enabled.
Returns
Boolean True when the _method request parameter is enabled, false otherwise
|
public
mixed
|
#
get( string $key, mixed $default = null, Boolean $deep = false )
Gets a "parameter" value.
Gets a "parameter" value.
This method is mainly useful for libraries that want to provide some
flexibility.
Order of precedence: GET, PATH, POST
Avoid using this method in controllers:
* slow * prefer to get from a "named" source
It is better to explicitly get request parameters from the appropriate public
property instead (query, attributes, request).
Parameters
- $key
string $key the key
- $default
mixed $default the default value
- $deep
Boolean $deep is parameter deep in multidimensional array
Returns
mixed
|
public
Symfony\Component\HttpFoundation\Session\SessionInterface |null
|
|
public
Boolean
|
#
hasPreviousSession( )
Whether the request contains a Session which was started in one of the
previous requests.
Whether the request contains a Session which was started in one of the
previous requests.
Returns
Boolean
Api
|
public
Boolean
|
#
hasSession( )
Whether the request contains a Session object.
Whether the request contains a Session object.
This method does not give any information about the state of the session
object, like whether the session is started or not. It is just a way to check if
this Request is associated with a Session instance.
Returns
Boolean true when the Request contains a Session object, false otherwise
Api
|
public
|
|
public
string
|
#
getClientIp( )
Returns the client IP address.
Returns the client IP address.
This method can read the client IP address from the "X-Forwarded-For" header
when trusted proxies were set via "setTrustedProxies()". The "X-Forwarded-For"
header value is a comma+space separated list of IP addresses, the left-most
being the original client, and each successive proxy that passed the request
adding the IP address where it received the request from.
If your reverse proxy uses a different header name than "X-Forwarded-For",
("Client-Ip" for instance), configure it via "setTrustedHeaderName()" with the
"client-ip" key.
Returns
string The client IP address
See
Api
|
public
string
|
#
getScriptName( )
Returns current script name.
Returns current script name.
Returns
string
Api
|
public
string
|
#
getPathInfo( )
Returns the path being requested relative to the executed script.
|
public
string
|
#
getBasePath( )
Returns the root path from which this request is executed.
|
public
string
|
#
getBaseUrl( )
Returns the root url from which this request is executed.
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.
Returns
string The raw url (i.e. not urldecoded)
Api
|
public
string
|
#
getScheme( )
Gets the request's scheme.
Gets the request's scheme.
Returns
string
Api
|
public
string
|
#
getPort( )
Returns the port on which the request is made.
Returns the port on which the request is made.
This method can read the client port from the "X-Forwarded-Port" header when
trusted proxies were set via "setTrustedProxies()".
The "X-Forwarded-Port" header must contain the client port.
If your reverse proxy uses a different header name than "X-Forwarded-Port",
configure it via "setTrustedHeaderName()" with the "client-port" key.
Returns
string
Api
|
public
string|null
|
#
getUser( )
Returns the user.
Returns
string|null
|
public
string|null
|
|
public
string
|
#
getUserInfo( )
Gets the user info.
Returns
string A user name and, optionally, scheme-specific information about how to gain
authorization to access the server
|
public
string
|
#
getHttpHost( )
Returns the HTTP host being requested.
Returns the HTTP host being requested.
The port name will be appended to the host if it's non-standard.
Returns
string
Api
|
public
string
|
#
getRequestUri( )
Returns the requested URI.
Returns the requested URI.
Returns
string The raw URI (i.e. not urldecoded)
Api
|
public
string
|
#
getSchemeAndHttpHost( )
Gets the scheme and HTTP host.
Gets the scheme and HTTP host.
If the URL was called with basic authentication, the user and the password
are not added to the generated string.
Returns
string The scheme and HTTP host
|
public
string
|
#
getUri( )
Generates a normalized URI for the Request.
Generates a normalized URI for the Request.
Returns
string A normalized URI for the Request
See
Api
|
public
string
|
#
getUriForPath( string $path )
Generates a normalized URI for the given path.
Generates a normalized URI for the given path.
Parameters
- $path
string $path A path to use instead of the current one
Returns
string The normalized URI for the path
Api
|
public
string|null
|
#
getQueryString( )
Generates the normalized query string for the Request.
Generates the normalized query string for the Request.
It builds a normalized query string, where keys/value pairs are alphabetized
and have consistent escaping.
Returns
string|null A normalized query string for the Request
Api
|
public
Boolean
|
#
isSecure( )
Checks whether the request is secure or not.
Checks whether the request is secure or not.
This method can read the client port from the "X-Forwarded-Proto" header when
trusted proxies were set via "setTrustedProxies()".
The "X-Forwarded-Proto" header must contain the protocol: "https" or
"http".
If your reverse proxy uses a different header name than "X-Forwarded-Proto"
("SSL_HTTPS" for instance), configure it via "setTrustedHeaderName()" with the
"client-proto" key.
Returns
Boolean
Api
|
public
string
|
#
getHost( )
Returns the host name.
This method can read the client port from the "X-Forwarded-Host" header when
trusted proxies were set via "setTrustedProxies()".
The "X-Forwarded-Host" header must contain the client host name.
If your reverse proxy uses a different header name than "X-Forwarded-Host",
configure it via "setTrustedHeaderName()" with the "client-host" key.
Returns
string
Throws
Api
|
public
|
#
setMethod( string $method )
Sets the request method.
Parameters
Api
|
public
string
|
#
getMethod( )
Gets the request "intended" method.
Gets the request "intended" method.
If the X-HTTP-Method-Override header is set, and if the method is a POST,
then it is used to determine the "real" intended HTTP method.
The _method request parameter can also be used to determine the HTTP method,
but only if enableHttpMethodParameterOverride() has been called.
The method is always an uppercased string.
Returns
string The request method
See
Api
|
public
string
|
#
getRealMethod( )
Gets the "real" request method.
Gets the "real" request method.
Returns
string The request method
See
|
public
string
|
#
getMimeType( string $format )
Gets the mime type associated with the format.
Gets the mime type associated with the format.
Parameters
- $format
string $format The format
Returns
string The associated mime type (null if not found)
Api
|
public
string|null
|
#
getFormat( string $mimeType )
Gets the format associated with the mime type.
Gets the format associated with the mime type.
Parameters
- $mimeType
string $mimeType The associated mime type
Returns
string|null The format (null if not found)
Api
|
public
|
#
setFormat( string $format, string|array $mimeTypes )
Associates a format with mime types.
Associates a format with mime types.
Parameters
- $format
string $format The format
- $mimeTypes
string|array $mimeTypes The associated mime types (the preferred one must be the first as it
will be used as the content type)
Api
|
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
Parameters
- $default
string $default The default format
Returns
string The request format
Api
|
public
|
#
setRequestFormat( string $format )
Sets the request format.
Parameters
- $format
string $format The request format.
Api
|
public
string|null
|
#
getContentType( )
Gets the format associated with the request.
Gets the format associated with the request.
Returns
string|null The format (null if no content type is present)
Api
|
public
|
|
public
|
#
setLocale( string $locale )
Sets the locale.
Parameters
Api
|
public
string
|
|
public
Boolean
|
#
isMethod( string $method )
Checks if the request method is of specified type.
Checks if the request method is of specified type.
Parameters
- $method
string $method Uppercase request method (GET, POST etc).
Returns
Boolean
|
public
Boolean
|
#
isMethodSafe( )
Checks whether the method is safe or not.
Checks whether the method is safe or not.
Returns
Boolean
Api
|
public
string|resource
|
#
getContent( Boolean $asResource = false )
Returns the request body content.
Returns the request body content.
Parameters
- $asResource
Boolean $asResource If true, a resource will be returned
Returns
string|resource The request body content or a resource to read the body stream.
Throws
|
public
array
|
#
getETags( )
Gets the Etags.
Returns
array The entity tags
|
public
Boolean
|
|
public
string|null
|
#
getPreferredLanguage( array $locales = null )
Returns the preferred language.
Returns the preferred language.
Parameters
- $locales
array $locales An array of ordered available locales
Returns
string|null The preferred locale
Api
|
public
array
|
#
getLanguages( )
Gets a list of languages acceptable by the client browser.
Gets a list of languages acceptable by the client browser.
Returns
array Languages ordered in the user browser preferences
Api
|
public
array
|
#
getCharsets( )
Gets a list of charsets acceptable by the client browser.
Gets a list of charsets acceptable by the client browser.
Returns
array List of charsets in preferable order
Api
|
public
array
|
#
getAcceptableContentTypes( )
Gets a list of content types acceptable by the client browser
Gets a list of content types acceptable by the client browser
Returns
array List of content types in preferable order
Api
|
public
Boolean
|
#
isXmlHttpRequest( )
Returns true if the request is a XMLHttpRequest.
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 common JavaScript frameworks:
Returns
Boolean true if the request is an XMLHttpRequest, false otherwise
Link
Api
|
protected
|
|
protected
string
|
|
protected
string
|
|
protected
string
|
|
protected static
|
#
initializeFormats( )
Initializes HTTP request formats.
Initializes HTTP request formats.
|
private
|
#
setPhpDefaultLocale( string $locale )
Sets the default PHP locale.
Sets the default PHP locale.
Parameters
|
private
|
|