Documentation

Request
in package

Request represents an HTTP request.

The methods dealing with URL accept / return a raw path (% encoded):

  • getBasePath
  • getBaseUrl
  • getPathInfo
  • getRequestUri
  • getUri
  • getUriForPath
Tags
author

Fabien Potencier fabien@symfony.com

Table of Contents

HEADER_FORWARDED  = 0b1
HEADER_X_FORWARDED_ALL  = 0b1011110
HEADER_X_FORWARDED_AWS_ELB  = 0b11010
HEADER_X_FORWARDED_FOR  = 0b10
HEADER_X_FORWARDED_HOST  = 0b100
HEADER_X_FORWARDED_PORT  = 0b10000
HEADER_X_FORWARDED_PREFIX  = 0b100000
HEADER_X_FORWARDED_PROTO  = 0b1000
HEADER_X_FORWARDED_TRAEFIK  = 0b111110
METHOD_CONNECT  = 'CONNECT'
METHOD_DELETE  = 'DELETE'
METHOD_GET  = 'GET'
METHOD_HEAD  = 'HEAD'
METHOD_OPTIONS  = 'OPTIONS'
METHOD_PATCH  = 'PATCH'
METHOD_POST  = 'POST'
METHOD_PURGE  = 'PURGE'
METHOD_PUT  = 'PUT'
METHOD_TRACE  = 'TRACE'
FORWARDED_PARAMS  = [self::HEADER_X_FORWARDED_FOR => 'for', self::HEADER_X_FORWARDED_HOST => 'host', self::HEADER_X_FORWARDED_PROTO => 'proto', self::HEADER_X_FORWARDED_PORT => 'host']
TRUSTED_HEADERS  = [self::HEADER_FORWARDED => 'FORWARDED', self::HEADER_X_FORWARDED_FOR => 'X_FORWARDED_FOR', self::HEADER_X_FORWARDED_HOST => 'X_FORWARDED_HOST', self::HEADER_X_FORWARDED_PROTO => 'X_FORWARDED_PROTO', self::HEADER_X_FORWARDED_PORT => 'X_FORWARDED_PORT', self::HEADER_X_FORWARDED_PREFIX => 'X_FORWARDED_PREFIX']
Names for headers that can be trusted when using trusted proxies.
$attributes  : ParameterBag
Custom parameters.
$cookies  : InputBag
Cookies ($_COOKIE).
$files  : FileBag
Uploaded files ($_FILES).
$headers  : HeaderBag
Headers (taken from the $_SERVER).
$query  : InputBag
Query string parameters ($_GET).
$request  : InputBag
Request body parameters ($_POST).
$server  : ServerBag
Server and execution environment parameters ($_SERVER).
$acceptableContentTypes  : array<string|int, mixed>
$basePath  : string
$baseUrl  : string
$charsets  : array<string|int, mixed>
$content  : string|resource|false|null
$defaultLocale  : string
$encodings  : array<string|int, mixed>
$format  : string
$formats  : array<string|int, mixed>
$httpMethodParameterOverride  : mixed
$languages  : array<string|int, mixed>
$locale  : string|null
$method  : string
$pathInfo  : string
$requestFactory  : mixed
$requestUri  : string
$session  : SessionInterface|callable
$trustedHostPatterns  : array<string|int, string>
$trustedHosts  : array<string|int, string>
$trustedProxies  : array<string|int, string>
$isForwardedValid  : mixed
$isHostValid  : mixed
$isIisRewrite  : bool
$isSafeContentPreferred  : bool|null
$preferredFormat  : string|null
$trustedHeaderSet  : mixed
__clone()  : mixed
Clones the current request.
__construct()  : mixed
__toString()  : string
Returns the request as a string.
create()  : static
Creates a Request based on a given URI and configuration.
createFromGlobals()  : static
Creates a new request with values from PHP's super globals.
duplicate()  : static
Clones a request and overrides some of its parameters.
enableHttpMethodParameterOverride()  : mixed
Enables support for the _method request parameter to determine the intended HTTP method.
getAcceptableContentTypes()  : array<string|int, mixed>
Gets a list of content types acceptable by the client browser in preferable order.
getBasePath()  : string
Returns the root path from which this request is executed.
getBaseUrl()  : string
Returns the root URL from which this request is executed.
getCharsets()  : array<string|int, mixed>
Gets a list of charsets acceptable by the client browser in preferable order.
getClientIp()  : string|null
Returns the client IP address.
getClientIps()  : array<string|int, mixed>
Returns the client IP addresses.
getContent()  : string|resource
Returns the request body content.
getContentType()  : string|null
Gets the format associated with the request.
getDefaultLocale()  : string
Get the default locale.
getEncodings()  : array<string|int, mixed>
Gets a list of encodings acceptable by the client browser in preferable order.
getETags()  : array<string|int, mixed>
Gets the Etags.
getFormat()  : string|null
Gets the format associated with the mime type.
getHost()  : string
Returns the host name.
getHttpHost()  : string
Returns the HTTP host being requested.
getHttpMethodParameterOverride()  : bool
Checks whether support for the _method request parameter is enabled.
getLanguages()  : array<string|int, mixed>
Gets a list of languages acceptable by the client browser ordered in the user browser preferences.
getLocale()  : string
Get the locale.
getMethod()  : string
Gets the request "intended" method.
getMimeType()  : string|null
Gets the mime type associated with the format.
getMimeTypes()  : array<string|int, mixed>
Gets the mime types associated with the format.
getPassword()  : string|null
Returns the password.
getPathInfo()  : string
Returns the path being requested relative to the executed script.
getPort()  : int|string|null
Returns the port on which the request is made.
getPreferredFormat()  : string|null
Gets the preferred format for the response by inspecting, in the following order: * the request format set using setRequestFormat; * the values of the Accept HTTP header.
getPreferredLanguage()  : string|null
Returns the preferred language.
getProtocolVersion()  : string|null
Returns the protocol version.
getQueryString()  : string|null
Generates the normalized query string for the Request.
getRealMethod()  : string
Gets the "real" request method.
getRelativeUriForPath()  : string
Returns the path as relative reference from the current Request path.
getRequestFormat()  : string|null
Gets the request format.
getRequestUri()  : string
Returns the requested URI (path and query string).
getScheme()  : string
Gets the request's scheme.
getSchemeAndHttpHost()  : string
Gets the scheme and HTTP host.
getScriptName()  : string
Returns current script name.
getSession()  : SessionInterface
Gets the Session.
getTrustedHeaderSet()  : int
Gets the set of trusted headers from trusted proxies.
getTrustedHosts()  : array<string|int, mixed>
Gets the list of trusted host patterns.
getTrustedProxies()  : array<string|int, mixed>
Gets the list of trusted proxies.
getUri()  : string
Generates a normalized URI (URL) for the Request.
getUriForPath()  : string
Generates a normalized URI for the given path.
getUser()  : string|null
Returns the user.
getUserInfo()  : string|null
Gets the user info.
hasPreviousSession()  : bool
Whether the request contains a Session which was started in one of the previous requests.
hasSession()  : bool
Whether the request contains a Session object.
initialize()  : mixed
Sets the parameters for this request.
isFromTrustedProxy()  : bool
Indicates whether this request originated from a trusted proxy.
isMethod()  : bool
Checks if the request method is of specified type.
isMethodCacheable()  : bool
Checks whether the method is cacheable or not.
isMethodIdempotent()  : bool
Checks whether or not the method is idempotent.
isMethodSafe()  : bool
Checks whether or not the method is safe.
isNoCache()  : bool
isSecure()  : bool
Checks whether the request is secure or not.
isXmlHttpRequest()  : bool
Returns true if the request is an XMLHttpRequest.
normalizeQueryString()  : string
Normalizes a query string.
overrideGlobals()  : mixed
Overrides the PHP global variables according to this request instance.
preferSafeContent()  : bool
Checks whether the client browser prefers safe content or not according to RFC8674.
setDefaultLocale()  : mixed
Sets the default locale.
setFactory()  : mixed
Sets a callable able to create a Request instance.
setFormat()  : mixed
Associates a format with mime types.
setLocale()  : mixed
Sets the locale.
setMethod()  : mixed
Sets the request method.
setRequestFormat()  : mixed
Sets the request format.
setSession()  : mixed
setTrustedHosts()  : mixed
Sets a list of trusted host patterns.
setTrustedProxies()  : mixed
Sets a list of trusted proxies.
toArray()  : array<string|int, mixed>
Gets the request body decoded as array, typically from a JSON payload.
initializeFormats()  : mixed
Initializes HTTP request formats.
prepareBasePath()  : string
Prepares the base path.
prepareBaseUrl()  : string
Prepares the base URL.
preparePathInfo()  : string
Prepares the path info.
prepareRequestUri()  : mixed
createRequestFromFactory()  : self
getBaseUrlReal()  : string
Returns the real base URL received by the webserver from which this request is executed.
getTrustedValues()  : array<string|int, mixed>
getUrlencodedPrefix()  : string|null
Returns the prefix as encoded in the string when the string starts with the given prefix, null otherwise.
isIisRewrite()  : bool
Is this IIS with UrlRewriteModule?
normalizeAndFilterClientIps()  : array<string|int, mixed>
setPhpDefaultLocale()  : void

Constants

HEADER_FORWARDED

public mixed HEADER_FORWARDED = 0b1

HEADER_X_FORWARDED_ALL

public mixed HEADER_X_FORWARDED_ALL = 0b1011110
Tags
deprecated

since Symfony 5.2, use either "HEADER_X_FORWARDED_FOR | HEADER_X_FORWARDED_HOST | HEADER_X_FORWARDED_PORT | HEADER_X_FORWARDED_PROTO" or "HEADER_X_FORWARDED_AWS_ELB" or "HEADER_X_FORWARDED_TRAEFIK" constants instead.

HEADER_X_FORWARDED_AWS_ELB

public mixed HEADER_X_FORWARDED_AWS_ELB = 0b11010

HEADER_X_FORWARDED_FOR

public mixed HEADER_X_FORWARDED_FOR = 0b10

HEADER_X_FORWARDED_HOST

public mixed HEADER_X_FORWARDED_HOST = 0b100

HEADER_X_FORWARDED_PORT

public mixed HEADER_X_FORWARDED_PORT = 0b10000

HEADER_X_FORWARDED_PREFIX

public mixed HEADER_X_FORWARDED_PREFIX = 0b100000

HEADER_X_FORWARDED_PROTO

public mixed HEADER_X_FORWARDED_PROTO = 0b1000

HEADER_X_FORWARDED_TRAEFIK

public mixed HEADER_X_FORWARDED_TRAEFIK = 0b111110

METHOD_CONNECT

public mixed METHOD_CONNECT = 'CONNECT'

METHOD_DELETE

public mixed METHOD_DELETE = 'DELETE'

METHOD_GET

public mixed METHOD_GET = 'GET'

METHOD_HEAD

public mixed METHOD_HEAD = 'HEAD'

METHOD_OPTIONS

public mixed METHOD_OPTIONS = 'OPTIONS'

METHOD_PATCH

public mixed METHOD_PATCH = 'PATCH'

METHOD_POST

public mixed METHOD_POST = 'POST'

METHOD_PURGE

public mixed METHOD_PURGE = 'PURGE'

METHOD_PUT

public mixed METHOD_PUT = 'PUT'

METHOD_TRACE

public mixed METHOD_TRACE = 'TRACE'

FORWARDED_PARAMS

private mixed FORWARDED_PARAMS = [self::HEADER_X_FORWARDED_FOR => 'for', self::HEADER_X_FORWARDED_HOST => 'host', self::HEADER_X_FORWARDED_PROTO => 'proto', self::HEADER_X_FORWARDED_PORT => 'host']

TRUSTED_HEADERS

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

private mixed TRUSTED_HEADERS = [self::HEADER_FORWARDED => 'FORWARDED', self::HEADER_X_FORWARDED_FOR => 'X_FORWARDED_FOR', self::HEADER_X_FORWARDED_HOST => 'X_FORWARDED_HOST', self::HEADER_X_FORWARDED_PROTO => 'X_FORWARDED_PROTO', self::HEADER_X_FORWARDED_PORT => 'X_FORWARDED_PORT', self::HEADER_X_FORWARDED_PREFIX => 'X_FORWARDED_PREFIX']

The FORWARDED header is the standard as of rfc7239.

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

Properties

$server

Server and execution environment parameters ($_SERVER).

public ServerBag $server

$acceptableContentTypes

protected array<string|int, mixed> $acceptableContentTypes

$basePath

protected string $basePath

$charsets

protected array<string|int, mixed> $charsets

$content

protected string|resource|false|null $content

$defaultLocale

protected string $defaultLocale = 'en'

$encodings

protected array<string|int, mixed> $encodings

$formats

protected static array<string|int, mixed> $formats

$httpMethodParameterOverride

protected static mixed $httpMethodParameterOverride = false

$languages

protected array<string|int, mixed> $languages

$locale

protected string|null $locale

$pathInfo

protected string $pathInfo

$requestFactory

protected static mixed $requestFactory

$requestUri

protected string $requestUri

$trustedHostPatterns

protected static array<string|int, string> $trustedHostPatterns = []

$trustedHosts

protected static array<string|int, string> $trustedHosts = []

$trustedProxies

protected static array<string|int, string> $trustedProxies = []

$isForwardedValid

private mixed $isForwardedValid = true

$isHostValid

private mixed $isHostValid = true

$isIisRewrite

private bool $isIisRewrite = false

$isSafeContentPreferred

private bool|null $isSafeContentPreferred

$preferredFormat

private string|null $preferredFormat

$trustedHeaderSet

private static mixed $trustedHeaderSet = -1

Methods

__clone()

Clones the current request.

public __clone() : mixed

Note that the session is not cloned as duplicated requests are most of the time sub-requests of the main one.

Return values
mixed

__construct()

public __construct([array<string|int, mixed> $query = [] ][, array<string|int, mixed> $request = [] ][, array<string|int, mixed> $attributes = [] ][, array<string|int, mixed> $cookies = [] ][, array<string|int, mixed> $files = [] ][, array<string|int, mixed> $server = [] ][, string|resource|null $content = null ]) : mixed
Parameters
$query : array<string|int, mixed> = []

The GET parameters

$request : array<string|int, mixed> = []

The POST parameters

$attributes : array<string|int, mixed> = []

The request attributes (parameters parsed from the PATH_INFO, ...)

$cookies : array<string|int, mixed> = []

The COOKIE parameters

$files : array<string|int, mixed> = []

The FILES parameters

$server : array<string|int, mixed> = []

The SERVER parameters

$content : string|resource|null = null

The raw body data

Return values
mixed

__toString()

Returns the request as a string.

public __toString() : string
Return values
string

create()

Creates a Request based on a given URI and configuration.

public static create(string $uri[, string $method = 'GET' ][, array<string|int, mixed> $parameters = [] ][, array<string|int, mixed> $cookies = [] ][, array<string|int, mixed> $files = [] ][, array<string|int, mixed> $server = [] ][, string|resource|null $content = null ]) : static

The information contained in the URI always take precedence over the other information (server and parameters).

Parameters
$uri : string

The URI

$method : string = 'GET'

The HTTP method

$parameters : array<string|int, mixed> = []

The query (GET) or request (POST) parameters

$cookies : array<string|int, mixed> = []

The request cookies ($_COOKIE)

$files : array<string|int, mixed> = []

The request files ($_FILES)

$server : array<string|int, mixed> = []

The server parameters ($_SERVER)

$content : string|resource|null = null

The raw body data

Return values
static

createFromGlobals()

Creates a new request with values from PHP's super globals.

public static createFromGlobals() : static
Return values
static

duplicate()

Clones a request and overrides some of its parameters.

public duplicate([array<string|int, mixed>|null $query = null ][, array<string|int, mixed>|null $request = null ][, array<string|int, mixed>|null $attributes = null ][, array<string|int, mixed>|null $cookies = null ][, array<string|int, mixed>|null $files = null ][, array<string|int, mixed>|null $server = null ]) : static
Parameters
$query : array<string|int, mixed>|null = null

The GET parameters

$request : array<string|int, mixed>|null = null

The POST parameters

$attributes : array<string|int, mixed>|null = null

The request attributes (parameters parsed from the PATH_INFO, ...)

$cookies : array<string|int, mixed>|null = null

The COOKIE parameters

$files : array<string|int, mixed>|null = null

The FILES parameters

$server : array<string|int, mixed>|null = null

The SERVER parameters

Return values
static

enableHttpMethodParameterOverride()

Enables support for the _method request parameter to determine the intended HTTP method.

public static enableHttpMethodParameterOverride() : mixed

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.

Return values
mixed

getAcceptableContentTypes()

Gets a list of content types acceptable by the client browser in preferable order.

public getAcceptableContentTypes() : array<string|int, mixed>
Return values
array<string|int, mixed>

getBasePath()

Returns the root path from which this request is executed.

public getBasePath() : string

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'
Return values
string

The raw path (i.e. not urldecoded)

getBaseUrl()

Returns the root URL from which this request is executed.

public getBaseUrl() : string

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.

Return values
string

The raw URL (i.e. not urldecoded)

getCharsets()

Gets a list of charsets acceptable by the client browser in preferable order.

public getCharsets() : array<string|int, mixed>
Return values
array<string|int, mixed>

getClientIp()

Returns the client IP address.

public getClientIp() : string|null

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 the $trustedHeaderSet argument of the Request::setTrustedProxies() method instead.

Tags
see
getClientIps()
see
https://wikipedia.org/wiki/X-Forwarded-For
Return values
string|null

getClientIps()

Returns the client IP addresses.

public getClientIps() : array<string|int, mixed>

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.

Tags
see
getClientIp()
Return values
array<string|int, mixed>

getContent()

Returns the request body content.

public getContent([bool $asResource = false ]) : string|resource
Parameters
$asResource : bool = false

If true, a resource will be returned

Return values
string|resource

getContentType()

Gets the format associated with the request.

public getContentType() : string|null
Return values
string|null

getDefaultLocale()

Get the default locale.

public getDefaultLocale() : string
Return values
string

getEncodings()

Gets a list of encodings acceptable by the client browser in preferable order.

public getEncodings() : array<string|int, mixed>
Return values
array<string|int, mixed>

getETags()

Gets the Etags.

public getETags() : array<string|int, mixed>
Return values
array<string|int, mixed>

getFormat()

Gets the format associated with the mime type.

public getFormat(string|null $mimeType) : string|null
Parameters
$mimeType : string|null
Return values
string|null

getHost()

Returns the host name.

public getHost() : string

This method can read the client host name from the "X-Forwarded-Host" header when trusted proxies were set via "setTrustedProxies()".

The "X-Forwarded-Host" header must contain the client host name.

Tags
throws
SuspiciousOperationException

when the host name is invalid or not trusted

Return values
string

getHttpHost()

Returns the HTTP host being requested.

public getHttpHost() : string

The port name will be appended to the host if it's non-standard.

Return values
string

getHttpMethodParameterOverride()

Checks whether support for the _method request parameter is enabled.

public static getHttpMethodParameterOverride() : bool
Return values
bool

getLanguages()

Gets a list of languages acceptable by the client browser ordered in the user browser preferences.

public getLanguages() : array<string|int, mixed>
Return values
array<string|int, mixed>

getLocale()

Get the locale.

public getLocale() : string
Return values
string

getMethod()

Gets the request "intended" method.

public getMethod() : string

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.

Tags
see
getRealMethod()
Return values
string

getMimeType()

Gets the mime type associated with the format.

public getMimeType(string $format) : string|null
Parameters
$format : string
Return values
string|null

getMimeTypes()

Gets the mime types associated with the format.

public static getMimeTypes(string $format) : array<string|int, mixed>
Parameters
$format : string
Return values
array<string|int, mixed>

getPassword()

Returns the password.

public getPassword() : string|null
Return values
string|null

getPathInfo()

Returns the path being requested relative to the executed script.

public getPathInfo() : string

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'
Return values
string

The raw path (i.e. not urldecoded)

getPort()

Returns the port on which the request is made.

public getPort() : int|string|null

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.

Return values
int|string|null

Can be a string if fetched from the server bag

getPreferredFormat()

Gets the preferred format for the response by inspecting, in the following order: * the request format set using setRequestFormat; * the values of the Accept HTTP header.

public getPreferredFormat([string|null $default = 'html' ]) : string|null

Note that if you use this method, you should send the "Vary: Accept" header in the response to prevent any issues with intermediary HTTP caches.

Parameters
$default : string|null = 'html'
Return values
string|null

getPreferredLanguage()

Returns the preferred language.

public getPreferredLanguage([array<string|int, string> $locales = null ]) : string|null
Parameters
$locales : array<string|int, string> = null

An array of ordered available locales

Return values
string|null

getProtocolVersion()

Returns the protocol version.

public getProtocolVersion() : string|null

If the application is behind a proxy, the protocol version used in the requests between the client and the proxy and between the proxy and the server might be different. This returns the former (from the "Via" header) if the proxy is trusted (see "setTrustedProxies()"), otherwise it returns the latter (from the "SERVER_PROTOCOL" server parameter).

Return values
string|null

getQueryString()

Generates the normalized query string for the Request.

public getQueryString() : string|null

It builds a normalized query string, where keys/value pairs are alphabetized and have consistent escaping.

Return values
string|null

getRealMethod()

Gets the "real" request method.

public getRealMethod() : string
Tags
see
getMethod()
Return values
string

getRelativeUriForPath()

Returns the path as relative reference from the current Request path.

public getRelativeUriForPath(string $path) : string

Only the URIs path component (no schema, host etc.) is relevant and must be given. Both paths must be absolute and not contain relative parts. Relative URLs from one resource to another are useful when generating self-contained downloadable document archives. Furthermore, they can be used to reduce the link size in documents.

Example target paths, given a base path of "/a/b/c/d":

  • "/a/b/c/d" -> ""
  • "/a/b/c/" -> "./"
  • "/a/b/" -> "../"
  • "/a/b/c/other" -> "other"
  • "/a/x/y" -> "../../x/y"
Parameters
$path : string
Return values
string

getRequestFormat()

Gets the request format.

public getRequestFormat([string|null $default = 'html' ]) : string|null

Here is the process to determine the format:

  • format defined by the user (with setRequestFormat())
  • _format request attribute
  • $default
Parameters
$default : string|null = 'html'
Tags
see
getPreferredFormat
Return values
string|null

getRequestUri()

Returns the requested URI (path and query string).

public getRequestUri() : string
Return values
string

The raw URI (i.e. not URI decoded)

getScheme()

Gets the request's scheme.

public getScheme() : string
Return values
string

getSchemeAndHttpHost()

Gets the scheme and HTTP host.

public getSchemeAndHttpHost() : string

If the URL was called with basic authentication, the user and the password are not added to the generated string.

Return values
string

getScriptName()

Returns current script name.

public getScriptName() : string
Return values
string

getTrustedHeaderSet()

Gets the set of trusted headers from trusted proxies.

public static getTrustedHeaderSet() : int
Return values
int

A bit field of Request::HEADER_* that defines which headers are trusted from your proxies

getTrustedHosts()

Gets the list of trusted host patterns.

public static getTrustedHosts() : array<string|int, mixed>
Return values
array<string|int, mixed>

getTrustedProxies()

Gets the list of trusted proxies.

public static getTrustedProxies() : array<string|int, mixed>
Return values
array<string|int, mixed>

getUri()

Generates a normalized URI (URL) for the Request.

public getUri() : string
Tags
see
getQueryString()
Return values
string

getUriForPath()

Generates a normalized URI for the given path.

public getUriForPath(string $path) : string
Parameters
$path : string

A path to use instead of the current one

Return values
string

getUser()

Returns the user.

public getUser() : string|null
Return values
string|null

getUserInfo()

Gets the user info.

public getUserInfo() : string|null
Return values
string|null

A user name if any and, optionally, scheme-specific information about how to gain authorization to access the server

hasPreviousSession()

Whether the request contains a Session which was started in one of the previous requests.

public hasPreviousSession() : bool
Return values
bool

hasSession()

Whether the request contains a Session object.

public hasSession() : bool

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.

Return values
bool

initialize()

Sets the parameters for this request.

public initialize([array<string|int, mixed> $query = [] ][, array<string|int, mixed> $request = [] ][, array<string|int, mixed> $attributes = [] ][, array<string|int, mixed> $cookies = [] ][, array<string|int, mixed> $files = [] ][, array<string|int, mixed> $server = [] ][, string|resource|null $content = null ]) : mixed

This method also re-initializes all properties.

Parameters
$query : array<string|int, mixed> = []

The GET parameters

$request : array<string|int, mixed> = []

The POST parameters

$attributes : array<string|int, mixed> = []

The request attributes (parameters parsed from the PATH_INFO, ...)

$cookies : array<string|int, mixed> = []

The COOKIE parameters

$files : array<string|int, mixed> = []

The FILES parameters

$server : array<string|int, mixed> = []

The SERVER parameters

$content : string|resource|null = null

The raw body data

Return values
mixed

isFromTrustedProxy()

Indicates whether this request originated from a trusted proxy.

public isFromTrustedProxy() : bool

This can be useful to determine whether or not to trust the contents of a proxy-specific header.

Return values
bool

isMethod()

Checks if the request method is of specified type.

public isMethod(string $method) : bool
Parameters
$method : string

Uppercase request method (GET, POST etc)

Return values
bool

isMethodIdempotent()

Checks whether or not the method is idempotent.

public isMethodIdempotent() : bool
Return values
bool

isNoCache()

public isNoCache() : bool
Return values
bool

isSecure()

Checks whether the request is secure or not.

public isSecure() : bool

This method can read the client protocol 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".

Return values
bool

normalizeQueryString()

Normalizes a query string.

public static normalizeQueryString(string|null $qs) : string

It builds a normalized query string, where keys/value pairs are alphabetized, have consistent escaping and unneeded delimiters are removed.

Parameters
$qs : string|null
Return values
string

overrideGlobals()

Overrides the PHP global variables according to this request instance.

public overrideGlobals() : mixed

It overrides $_GET, $_POST, $_REQUEST, $_SERVER, $_COOKIE. $_FILES is never overridden, see rfc1867

Return values
mixed

setDefaultLocale()

Sets the default locale.

public setDefaultLocale(string $locale) : mixed
Parameters
$locale : string
Return values
mixed

setFactory()

Sets a callable able to create a Request instance.

public static setFactory(callable|null $callable) : mixed

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 : callable|null
Return values
mixed

setFormat()

Associates a format with mime types.

public setFormat(string|null $format, string|array<string|int, mixed> $mimeTypes) : mixed
Parameters
$format : string|null
$mimeTypes : string|array<string|int, mixed>

The associated mime types (the preferred one must be the first as it will be used as the content type)

Return values
mixed

setLocale()

Sets the locale.

public setLocale(string $locale) : mixed
Parameters
$locale : string
Return values
mixed

setMethod()

Sets the request method.

public setMethod(string $method) : mixed
Parameters
$method : string
Return values
mixed

setRequestFormat()

Sets the request format.

public setRequestFormat(string|null $format) : mixed
Parameters
$format : string|null
Return values
mixed

setTrustedHosts()

Sets a list of trusted host patterns.

public static setTrustedHosts(array<string|int, mixed> $hostPatterns) : mixed

You should only list the hosts you manage using regexs.

Parameters
$hostPatterns : array<string|int, mixed>

A list of trusted host patterns

Return values
mixed

setTrustedProxies()

Sets a list of trusted proxies.

public static setTrustedProxies(array<string|int, mixed> $proxies, int $trustedHeaderSet) : mixed

You should only list the reverse proxies that you manage directly.

Parameters
$proxies : array<string|int, mixed>

A list of trusted proxies, the string 'REMOTE_ADDR' will be replaced with $_SERVER['REMOTE_ADDR']

$trustedHeaderSet : int

A bit field of Request::HEADER_*, to set which headers to trust from your proxies

Return values
mixed

toArray()

Gets the request body decoded as array, typically from a JSON payload.

public toArray() : array<string|int, mixed>
Tags
throws
JsonException

When the body cannot be decoded to an array

Return values
array<string|int, mixed>

initializeFormats()

Initializes HTTP request formats.

protected static initializeFormats() : mixed
Return values
mixed

prepareBasePath()

Prepares the base path.

protected prepareBasePath() : string
Return values
string

prepareBaseUrl()

Prepares the base URL.

protected prepareBaseUrl() : string
Return values
string

preparePathInfo()

Prepares the path info.

protected preparePathInfo() : string
Return values
string

prepareRequestUri()

protected prepareRequestUri() : mixed
Return values
mixed

createRequestFromFactory()

private static createRequestFromFactory([array<string|int, mixed> $query = [] ][, array<string|int, mixed> $request = [] ][, array<string|int, mixed> $attributes = [] ][, array<string|int, mixed> $cookies = [] ][, array<string|int, mixed> $files = [] ][, array<string|int, mixed> $server = [] ][, mixed $content = null ]) : self
Parameters
$query : array<string|int, mixed> = []
$request : array<string|int, mixed> = []
$attributes : array<string|int, mixed> = []
$cookies : array<string|int, mixed> = []
$files : array<string|int, mixed> = []
$server : array<string|int, mixed> = []
$content : mixed = null
Return values
self

getBaseUrlReal()

Returns the real base URL received by the webserver from which this request is executed.

private getBaseUrlReal() : string

The URL does not include trusted reverse proxy prefix.

Return values
string

The raw URL (i.e. not urldecoded)

getTrustedValues()

private getTrustedValues(int $type[, string|null $ip = null ]) : array<string|int, mixed>
Parameters
$type : int
$ip : string|null = null
Return values
array<string|int, mixed>

getUrlencodedPrefix()

Returns the prefix as encoded in the string when the string starts with the given prefix, null otherwise.

private getUrlencodedPrefix(string $string, string $prefix) : string|null
Parameters
$string : string
$prefix : string
Return values
string|null

isIisRewrite()

Is this IIS with UrlRewriteModule?

private isIisRewrite() : bool

This method consumes, caches and removed the IIS_WasUrlRewritten env var, so we don't inherit it to sub-requests.

Return values
bool

normalizeAndFilterClientIps()

private normalizeAndFilterClientIps(array<string|int, mixed> $clientIps, string $ip) : array<string|int, mixed>
Parameters
$clientIps : array<string|int, mixed>
$ip : string
Return values
array<string|int, mixed>

setPhpDefaultLocale()

private setPhpDefaultLocale(string $locale) : void
Parameters
$locale : string
Return values
void

Search results