FileAccess Orion

ApacheRequest extends Request
in package

Request represents an HTTP request from an Apache server.

Tags
deprecated

since Symfony 4.4. Use the Request class instead.

author

Fabien Potencier fabien@symfony.com

Table of Contents

HEADER_FORWARDED  = 0b1
HEADER_X_FORWARDED_ALL  = 0b11110
HEADER_X_FORWARDED_AWS_ELB  = 0b11010
HEADER_X_FORWARDED_FOR  = 0b10
HEADER_X_FORWARDED_HOST  = 0b100
HEADER_X_FORWARDED_PORT  = 0b10000
HEADER_X_FORWARDED_PROTO  = 0b1000
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'
$attributes  : ParameterBag
Custom parameters.
$cookies  : ParameterBag
Cookies ($_COOKIE).
$files  : FileBag
Uploaded files ($_FILES).
$headers  : HeaderBag
Headers (taken from the $_SERVER).
$query  : ParameterBag
Query string parameters ($_GET).
$request  : ParameterBag
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
$method  : string
$pathInfo  : string
$requestFactory  : mixed
$requestUri  : string
$session  : SessionInterface
$trustedHostPatterns  : array<string|int, string>
$trustedHosts  : array<string|int, string>
$trustedProxies  : array<string|int, string>
$forwardedParams  : mixed
$isForwardedValid  : mixed
$isHostValid  : mixed
$preferredFormat  : string|null
$trustedHeaders  : mixed
Names for headers that can be trusted when using trusted proxies.
$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.
get()  : mixed
Gets a "parameter" value from any bag.
getAcceptableContentTypes()  : array<string|int, mixed>
Gets a list of content types acceptable by the client browser.
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.
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.
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.
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
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
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
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 a XMLHttpRequest.
normalizeQueryString()  : string
Normalizes a query string.
overrideGlobals()  : mixed
Overrides the PHP global variables according to this request instance.
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.
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
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.
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 = 0b11110

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_PROTO

public mixed HEADER_X_FORWARDED_PROTO = 0b1000

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'

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

$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 = []

$forwardedParams

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

$isForwardedValid

private mixed $isForwardedValid = true

$isHostValid

private mixed $isHostValid = true

$preferredFormat

private string|null $preferredFormat

$trustedHeaders

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

private static mixed $trustedHeaders = [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']

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

$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

The request

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> $query = null ][, array<string|int, mixed> $request = null ][, array<string|int, mixed> $attributes = null ][, array<string|int, mixed> $cookies = null ][, array<string|int, mixed> $files = null ][, array<string|int, mixed> $server = null ]) : static
Parameters
$query : array<string|int, mixed> = null

The GET parameters

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

The POST parameters

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

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

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

The COOKIE parameters

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

The FILES parameters

$server : array<string|int, mixed> = 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

get()

Gets a "parameter" value from any bag.

public get(string $key[, mixed $default = null ]) : mixed

This method is mainly useful for libraries that want to provide some flexibility. If you don't need the flexibility in controllers, it is better to explicitly get request parameters from the appropriate public property instead (attributes, query, request).

Order of precedence: PATH (routing placeholders or custom attributes), GET, BODY

Parameters
$key : string

The key

$default : mixed = null

The default value if the parameter key does not exist

Return values
mixed

getAcceptableContentTypes()

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

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

List of content types in preferable order

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.

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

List of charsets in preferable order

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

The client IP address

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>

The client IP addresses

getContent()

Returns the request body content.

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

If true, a resource will be returned

Tags
throws
LogicException
Return values
string|resource

The request body content or a resource to read the body stream

getContentType()

Gets the format associated with the request.

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

The format (null if no content type is present)

getDefaultLocale()

Get the default locale.

public getDefaultLocale() : string
Return values
string

getEncodings()

Gets a list of encodings acceptable by the client browser.

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

List of encodings in preferable order

getETags()

Gets the Etags.

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

The entity tags

getFormat()

Gets the format associated with the mime type.

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

The associated mime type

Return values
string|null

The format (null if not found)

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

True when the _method request parameter is enabled, false otherwise

getLanguages()

Gets a list of languages acceptable by the client browser.

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

Languages ordered in the user browser preferences

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

The request method

getMimeType()

Gets the mime type associated with the format.

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

The format

Return values
string|null

The associated mime type (null if not found)

getMimeTypes()

Gets the mime types associated with the format.

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

The format

Return values
array<string|int, mixed>

The associated mime types

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

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

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

The preferred locale

getProtocolVersion()

Returns the protocol version.

public getProtocolVersion() : string

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

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

A normalized query string for the Request

getRealMethod()

Gets the "real" request method.

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

The request method

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

The target path

Return values
string

The relative target path

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'

The default format

Tags
see
getPreferredFormat
Return values
string|null

The request format

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

The scheme and HTTP host

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>

An array of trusted host patterns

getTrustedProxies()

Gets the list of trusted proxies.

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

An array of trusted proxies

getUri()

Generates a normalized URI (URL) for the Request.

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

A normalized URI (URL) for the Request

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

The normalized URI for the path

getUser()

Returns the user.

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

getUserInfo()

Gets the user info.

public getUserInfo() : string
Return values
string

A user name 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

true when the Request contains a Session object, false otherwise

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

true if the request came from a trusted proxy, false otherwise

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

isXmlHttpRequest()

Returns true if the request is a XMLHttpRequest.

public isXmlHttpRequest() : bool

It works if your JavaScript library sets an X-Requested-With HTTP header. It is known to work with common JavaScript frameworks:

Tags
see
https://wikipedia.org/wiki/List_of_Ajax_frameworks#JavaScript
Return values
bool

true if the request is an XMLHttpRequest, false otherwise

normalizeQueryString()

Normalizes a query string.

public static normalizeQueryString(string $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

Query string

Return values
string

A normalized query string for the Request

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

A PHP callable

Return values
mixed

setFormat()

Associates a format with mime types.

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

The format

$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 $format) : mixed
Parameters
$format : string

The request format

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

Tags
throws
InvalidArgumentException

When $trustedHeaderSet is invalid

Return values
mixed

initializeFormats()

Initializes HTTP request formats.

protected static initializeFormats() : mixed
Return values
mixed

prepareBasePath()

Prepares the base path.

protected prepareBasePath() : string
Return values
string

base path

prepareBaseUrl()

Prepares the base URL.

protected prepareBaseUrl() : string
Return values
string

preparePathInfo()

Prepares the path info.

protected preparePathInfo() : string
Return values
string

path info

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

getTrustedValues()

private getTrustedValues(int $type[, string $ip = null ]) : array<string|int, mixed>
Parameters
$type : int
$ip : string = 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

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