Overview

Namespaces

  • Composer
    • Autoload
  • Guzzle
    • Common
      • Exception
    • Http
      • Curl
      • Exception
      • Message
        • Header
      • QueryAggregator
    • Parser
      • Cookie
      • Message
      • UriTemplate
      • Url
    • Plugin
      • Mock
    • Stream
  • Mockery
    • Adapter
      • Phpunit
    • CountValidator
    • Exception
    • Generator
      • StringManipulation
        • Pass
    • Loader
    • Matcher
  • None
  • Omnipay
    • Common
      • Exception
      • Message
    • Dummy
      • Message
    • Fatzebra
      • Message
  • PHP
  • Symfony
    • Component
      • EventDispatcher
        • Debug
        • DependencyInjection
        • Tests
          • Debug
          • DependencyInjection
      • HttpFoundation
        • File
          • Exception
          • MimeType
        • Session
          • Attribute
          • Flash
          • Storage
            • Handler
            • Proxy
        • Tests
          • File
            • MimeType
          • Session
            • Attribute
            • Flash
            • Storage
              • Handler
              • Proxy
      • Yaml
        • Exception
        • Tests

Classes

  • AcceptHeader
  • AcceptHeaderItem
  • ApacheRequest
  • BinaryFileResponse
  • Cookie
  • ExpressionRequestMatcher
  • FileBag
  • HeaderBag
  • IpUtils
  • JsonResponse
  • ParameterBag
  • RedirectResponse
  • Request
  • RequestMatcher
  • RequestStack
  • Response
  • ResponseHeaderBag
  • ServerBag
  • StreamedResponse

Interfaces

  • RequestMatcherInterface
  • Overview
  • Namespace
  • Class
  • Tree

Class Request

Request represents an HTTP request.

The methods dealing with URL accept / return a raw path (% encoded): * getBasePath * getBaseUrl * getPathInfo * getRequestUri * getUri * getUriForPath

Direct known subclasses

Symfony\Component\HttpFoundation\ApacheRequest, Symfony\Component\HttpFoundation\Tests\NewRequest, Symfony\Component\HttpFoundation\Tests\RequestContentProxy
Namespace: Symfony\Component\HttpFoundation
Author: Fabien Potencier fabien@symfony.com
Api
Located at Request.php
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.

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

Symfony\Component\HttpFoundation\Request
A new request

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

Symfony\Component\HttpFoundation\Request
A Request instance

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

$callable
A PHP callable
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

Symfony\Component\HttpFoundation\Request
The duplicated request

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
# setTrustedHeaderName( string $key, string $value )

Sets the name for trusted headers.

Sets the name for trusted headers.

The following header keys are supported: * Request::HEADER_CLIENT_IP: defaults to X-Forwarded-For (see getClientIp()) * Request::HEADER_CLIENT_HOST: defaults to X-Forwarded-Host (see getClientHost()) * Request::HEADER_CLIENT_PORT: defaults to X-Forwarded-Port (see getClientPort()) * Request::HEADER_CLIENT_PROTO: defaults to X-Forwarded-Proto (see getScheme() and isSecure())

Setting an empty value allows to disable the trusted header for the given key.

Parameters

$key
The header key
$value
The header name

Throws

InvalidArgumentException
public static string
# getTrustedHeaderName( string $key )

Gets the trusted proxy header name.

Gets the trusted proxy header name.

Parameters

$key
The header key

Returns

string
The header name

Throws

InvalidArgumentException
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
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. 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
# getSession( )

Gets the Session.

Gets the Session.

Returns

Symfony\Component\HttpFoundation\Session\SessionInterface|null
The session

Api

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
# setSession( Symfony\Component\HttpFoundation\Session\SessionInterface $session )

Sets the Session.

Sets the Session.

Parameters

$session
The Session

Api

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

Symfony\Component\HttpFoundation\Request::getClientIp()
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

Symfony\Component\HttpFoundation\Request::getClientIps()
http://en.wikipedia.org/wiki/X-Forwarded-For

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 the user.

Returns

string|null
public string|null
# getPassword( )

Returns the password.

Returns the password.

Returns

string|null
public string
# getUserInfo( )

Gets the user info.

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

Symfony\Component\HttpFoundation\Request::getQueryString()

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.

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

UnexpectedValueException
when the host name is invalid

Api

public
# setMethod( string $method )

Sets the request method.

Sets the request method.

Parameters

$method

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

Symfony\Component\HttpFoundation\Request::getRealMethod()

Api

public string
# getRealMethod( )

Gets the "real" request method.

Gets the "real" request method.

Returns

string
The request method

See

Symfony\Component\HttpFoundation\Request::getMethod()
public string
# getMimeType( string $format )

Gets the mime type associated with the format.

Gets the mime type associated with the format.

Parameters

$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
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.

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.

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
# setDefaultLocale( string $locale )

Sets the default locale.

Sets the default locale.

Parameters

$locale

Api

public string
# getDefaultLocale( )

Get the default locale.

Get the default locale.

Returns

string
public
# setLocale( string $locale )

Sets the locale.

Sets the locale.

Parameters

$locale

Api

public string
# getLocale( )

Get the locale.

Get the locale.

Returns

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

LogicException
public array
# getETags( )

Gets the Etags.

Gets the Etags.

Returns

array
The entity tags
public boolean
# isNoCache( )

Returns

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

http://en.wikipedia.org/wiki/List_of_Ajax_frameworks#JavaScript

Api

protected
# prepareRequestUri( )
protected string
# prepareBaseUrl( )

Prepares the base URL.

Prepares the base URL.

Returns

string
protected string
# prepareBasePath( )

Prepares the base path.

Prepares the base path.

Returns

string
base path
protected string
# preparePathInfo( )

Prepares the path info.

Prepares the path info.

Returns

string
path info
protected static
# initializeFormats( )

Initializes HTTP request formats.

Initializes HTTP request formats.

Constants summary
string HEADER_CLIENT_IP
# 'client_ip'
string HEADER_CLIENT_HOST
# 'client_host'
string HEADER_CLIENT_PROTO
# 'client_proto'
string HEADER_CLIENT_PORT
# 'client_port'
string METHOD_HEAD
# 'HEAD'
string METHOD_GET
# 'GET'
string METHOD_POST
# 'POST'
string METHOD_PUT
# 'PUT'
string METHOD_PATCH
# 'PATCH'
string METHOD_DELETE
# 'DELETE'
string METHOD_PURGE
# 'PURGE'
string METHOD_OPTIONS
# 'OPTIONS'
string METHOD_TRACE
# 'TRACE'
string METHOD_CONNECT
# 'CONNECT'
Properties summary
protected static array $trustedProxies
# array()
protected static string[] $trustedHostPatterns
# array()
protected static string[] $trustedHosts
# array()
protected static array $trustedHeaders

Names for headers that can be trusted when using trusted proxies.

Names for headers that can be trusted when using trusted proxies.

The default names are non-standard, but widely used by popular reverse proxies (like Apache mod_proxy or Amazon EC2).

# array( self::HEADER_CLIENT_IP => 'X_FORWARDED_FOR', self::HEADER_CLIENT_HOST => 'X_FORWARDED_HOST', self::HEADER_CLIENT_PROTO => 'X_FORWARDED_PROTO', self::HEADER_CLIENT_PORT => 'X_FORWARDED_PORT', )
protected static boolean $httpMethodParameterOverride
# false
public Symfony\Component\HttpFoundation\ParameterBag $attributes

Custom parameters.

Custom parameters.

Api

#
public Symfony\Component\HttpFoundation\ParameterBag $request

Request body parameters ($_POST).

Request body parameters ($_POST).

Api

#
public Symfony\Component\HttpFoundation\ParameterBag $query

Query string parameters ($_GET).

Query string parameters ($_GET).

Api

#
public Symfony\Component\HttpFoundation\ServerBag $server

Server and execution environment parameters ($_SERVER).

Server and execution environment parameters ($_SERVER).

Api

#
public Symfony\Component\HttpFoundation\FileBag $files

Uploaded files ($_FILES).

Uploaded files ($_FILES).

Api

#
public Symfony\Component\HttpFoundation\ParameterBag $cookies

Cookies ($_COOKIE).

Cookies ($_COOKIE).

Api

#
public Symfony\Component\HttpFoundation\HeaderBag $headers

Headers (taken from the $_SERVER).

Headers (taken from the $_SERVER).

Api

#
protected string $content
#
protected array $languages
#
protected array $charsets
#
protected array $encodings
#
protected array $acceptableContentTypes
#
protected string $pathInfo
#
protected string $requestUri
#
protected string $baseUrl
#
protected string $basePath
#
protected string $method
#
protected string $format
#
protected Symfony\Component\HttpFoundation\Session\SessionInterface $session
#
protected string $locale
#
protected string $defaultLocale
# 'en'
protected static array $formats
#
protected static $requestFactory
#
Omnipay Fat Zebra / Paystream Gateway Module API Documentation API documentation generated by ApiGen