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
- The GET parameters
- $request
- The POST parameters
- $attributes
- The request attributes (parameters parsed from the PATH_INFO, ...)
- $cookies
- The COOKIE parameters
- $files
- The FILES parameters
- $server
- The SERVER parameters
- $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
- The GET parameters
- $request
- The POST parameters
- $attributes
- The request attributes (parameters parsed from the PATH_INFO, ...)
- $cookies
- The COOKIE parameters
- $files
- The FILES parameters
- $server
- The SERVER parameters
- $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
- The URI
- $method
- The HTTP method
- $parameters
- The query (GET) or request (POST) parameters
- $cookies
- The request cookies ($_COOKIE)
- $files
- The request files ($_FILES)
- $server
- The server parameters ($_SERVER)
- $content
- The raw body data
Returns
Api
|
public static
|
#
setFactory( callable|null $callable )
Sets a callable able to create a Request instance.
Sets a callable able to create a Request instance.
This is mainly useful when you need to override the Request class
to keep BC with an existing system. It should not be used for any
other purpose.
Parameters
|
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
- The GET parameters
- $request
- The POST parameters
- $attributes
- The request attributes (parameters parsed from the PATH_INFO, ...)
- $cookies
- The COOKIE parameters
- $files
- The FILES parameters
- $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 overridden, see rfc1867
Api
|
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
- 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
|
#
setTrustedHosts( array $hostPatterns )
Sets a list of trusted host patterns.
Sets a list of trusted host patterns.
You should only list the hosts you manage using regexs.
Parameters
- $hostPatterns
- A list of trusted host patterns
|
public static
array
|
#
getTrustedHosts( )
Gets the list of trusted host patterns.
Gets the list of trusted host patterns.
Returns
array An array of trusted host patterns.
|
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
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.
If the HTTP method parameter override is enabled, an html-form with method "POST" can be altered
and used to send a "PUT" or "DELETE" request via the _method request parameter.
If these methods are not protected against CSRF, this presents a possible vulnerability.
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
- the key
- $default
- the default value
- $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
array
|
#
getClientIps( )
Returns the client IP addresses.
Returns the client IP addresses.
In the returned array the most trusted IP address is first, and the
least trusted one last. The "real" client IP address is the last one,
but this is also the least trusted one. Trusted proxies are stripped.
Use this method carefully; you should use getClientIp() instead.
Returns
array The client IP addresses
See
|
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.
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/enco%20ded returns '/enco%20ded' * http://localhost/mysite/about?var=1 returns '/about'
Returns
string The raw path (i.e. not urldecoded)
Api
|
public
string
|
#
getBasePath( )
Returns the root path from which this request is executed.
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 returns '/web' * http://localhost/we%20b/index.php returns '/we%20b'
Returns
string The raw path (i.e. not urldecoded)
Api
|
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 (path and query string).
Returns the requested URI (path and query string).
Returns
string The raw URI (i.e. not URI decoded)
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 (URL) for the Request.
Generates a normalized URI (URL) for the Request.
Returns
string A normalized URI (URL) 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
- 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
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
- 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
- The format
- $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
- The default format
Returns
string The request format
Api
|
public
|
#
setRequestFormat( string $format )
Sets the request format.
Parameters
- $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
string
|
|
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
- 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
- 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
- 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
|
#
getEncodings( )
Gets a list of encodings acceptable by the client browser.
Gets a list of encodings acceptable by the client browser.
Returns
array List of encodings in preferable order
|
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 sets 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.
|