SymfonyComponentHttpFoundationLaravelRequest

Request represents an HTTP request.

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

  • getBasePath
  • getBaseUrl
  • getPathInfo
  • getRequestUri
  • getUri
  • getUriForPath

Summary

No private properties found
N/A
File
vendorSymfonyComponentHttpFoundationLaravelRequest.php
Package
Default
Class hierarchy
SymfonyComponentHttpFoundationLaravelRequest

Tags

None found

Constants

HEADER_CLIENT_IP

HEADER_CLIENT_IP

Inherited from
SymfonyComponentHttpFoundationRequest

Tags

None found

HEADER_CLIENT_HOST

HEADER_CLIENT_HOST

Inherited from
SymfonyComponentHttpFoundationRequest

Tags

None found

HEADER_CLIENT_PROTO

HEADER_CLIENT_PROTO

Inherited from
SymfonyComponentHttpFoundationRequest

Tags

None found

HEADER_CLIENT_PORT

HEADER_CLIENT_PORT

Inherited from
SymfonyComponentHttpFoundationRequest

Tags

None found

Properties

$attributes

$attributes : \Symfony\Component\HttpFoundation\ParameterBag

Type

SymfonyComponentHttpFoundationParameterBag

$request

$request : \Symfony\Component\HttpFoundation\ParameterBag

Type

SymfonyComponentHttpFoundationParameterBag

$query

$query : \Symfony\Component\HttpFoundation\ParameterBag

Type

SymfonyComponentHttpFoundationParameterBag

$server

$server : \Symfony\Component\HttpFoundation\ServerBag

Type

SymfonyComponentHttpFoundationServerBag

$files

$files : \Symfony\Component\HttpFoundation\FileBag

Type

SymfonyComponentHttpFoundationFileBag

$cookies

$cookies : \Symfony\Component\HttpFoundation\ParameterBag

Type

SymfonyComponentHttpFoundationParameterBag

$headers

$headers : \Symfony\Component\HttpFoundation\HeaderBag

Type

SymfonyComponentHttpFoundationHeaderBag

$trustProxy

$trustProxy : 

Type

Inherited from
SymfonyComponentHttpFoundationRequest

Tags

None found

$trustedProxies

$trustedProxies : 

Type

Inherited from
SymfonyComponentHttpFoundationRequest

Tags

None found

$trustedHeaders

$trustedHeaders : 

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

Type

Inherited from
SymfonyComponentHttpFoundationRequest

Tags

None found

$httpMethodParameterOverride

$httpMethodParameterOverride : 

Type

Inherited from
SymfonyComponentHttpFoundationRequest

Tags

None found

$content

$content : string

Type

string

Inherited from
SymfonyComponentHttpFoundationRequest

Tags

None found

$languages

$languages : array

Type

array

Inherited from
SymfonyComponentHttpFoundationRequest

Tags

None found

$charsets

$charsets : array

Type

array

Inherited from
SymfonyComponentHttpFoundationRequest

Tags

None found

$acceptableContentTypes

$acceptableContentTypes : array

Type

array

Inherited from
SymfonyComponentHttpFoundationRequest

Tags

None found

$pathInfo

$pathInfo : string

Type

string

Inherited from
SymfonyComponentHttpFoundationRequest

Tags

None found

$requestUri

$requestUri : string

Type

string

Inherited from
SymfonyComponentHttpFoundationRequest

Tags

None found

$baseUrl

$baseUrl : string

Type

string

Inherited from
SymfonyComponentHttpFoundationRequest

Tags

None found

$basePath

$basePath : string

Type

string

Inherited from
SymfonyComponentHttpFoundationRequest

Tags

None found

$method

$method : string

Type

string

Inherited from
SymfonyComponentHttpFoundationRequest

Tags

None found

$format

$format : string

Type

string

Inherited from
SymfonyComponentHttpFoundationRequest

Tags

None found

$session

$session : \Symfony\Component\HttpFoundation\Session\SessionInterface

Type

SymfonyComponentHttpFoundationSessionSessionInterface

Inherited from
SymfonyComponentHttpFoundationRequest

Tags

None found

$locale

$locale : string

Type

string

Inherited from
SymfonyComponentHttpFoundationRequest

Tags

None found

$defaultLocale

$defaultLocale : string

Type

string

Inherited from
SymfonyComponentHttpFoundationRequest

Tags

None found

$formats

$formats : array

Type

array

Inherited from
SymfonyComponentHttpFoundationRequest

Tags

None found

Methods

__construct()

__construct(array  $query = array(), array  $request = array(), array  $attributes = array(), array  $cookies = array(), array  $files = array(), array  $server = array(), string  $content = null) 

Constructor.

Parameters

array $query

The GET parameters

array $request

The POST parameters

array $attributes

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

array $cookies

The COOKIE parameters

array $files

The FILES parameters

array $server

The SERVER parameters

string $content

The raw body data

initialize()

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.

This method also re-initializes all properties.

Parameters

array $query

The GET parameters

array $request

The POST parameters

array $attributes

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

array $cookies

The COOKIE parameters

array $files

The FILES parameters

array $server

The SERVER parameters

string $content

The raw body data

createFromGlobals()

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

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

Returns

SymfonyComponentHttpFoundationRequest

A new request

static

Tags

api

create()

create(string  $uri, string  $method = 'GET', array  $parameters = array(), array  $cookies = array(), array  $files = array(), array  $server = array(), string  $content = null) : \Symfony\Component\HttpFoundation\Request

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

string $uri

The URI

string $method

The HTTP method

array $parameters

The query (GET) or request (POST) parameters

array $cookies

The request cookies ($_COOKIE)

array $files

The request files ($_FILES)

array $server

The server parameters ($_SERVER)

string $content

The raw body data

Returns

SymfonyComponentHttpFoundationRequest

A Request instance

static
Inherited from
SymfonyComponentHttpFoundationRequest

Tags

api

duplicate()

duplicate(array  $query = null, array  $request = null, array  $attributes = null, array  $cookies = null, array  $files = null, array  $server = null) : \Symfony\Component\HttpFoundation\Request

Clones a request and overrides some of its parameters.

Parameters

array $query

The GET parameters

array $request

The POST parameters

array $attributes

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

array $cookies

The COOKIE parameters

array $files

The FILES parameters

array $server

The SERVER parameters

Returns

SymfonyComponentHttpFoundationRequest

The duplicated request

__clone()

__clone() 

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.

Inherited from
SymfonyComponentHttpFoundationRequest

Tags

None found

__toString()

__toString() : string

Returns the request as a string.

Returns

string —

The request

Inherited from
SymfonyComponentHttpFoundationRequest

Tags

None found

overrideGlobals()

overrideGlobals() 

Overrides the PHP global variables according to this request instance.

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

trustProxyData()

trustProxyData() 

Trusts $_SERVER entries coming from proxies.

static

Deprecated

Deprecated since version 2.0, to be removed in 2.3. Use setTrustedProxies instead.
Inherited from
SymfonyComponentHttpFoundationRequest

Tags

None found

setTrustedProxies()

setTrustedProxies(array  $proxies) 

Sets a list of trusted proxies.

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

Parameters

array $proxies

A list of trusted proxies

static
Inherited from
SymfonyComponentHttpFoundationRequest

Tags

api

getTrustedProxies()

getTrustedProxies() : array

Gets the list of trusted proxies.

Returns

array —

An array of trusted proxies.

static
Inherited from
SymfonyComponentHttpFoundationRequest

Tags

None found

setTrustedHeaderName()

setTrustedHeaderName(string  $key, string  $value) 

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

string $key

The header key

string $value

The header name

Throws

InvalidArgumentException

static
Inherited from
SymfonyComponentHttpFoundationRequest

Tags

None found

isProxyTrusted()

isProxyTrusted() : boolean

Returns true if $_SERVER entries coming from proxies are trusted, false otherwise.

Returns

boolean

static

Deprecated

Deprecated since version 2.2, to be removed in 2.3. Use getTrustedProxies instead.
Inherited from
SymfonyComponentHttpFoundationRequest

Tags

None found

normalizeQueryString()

normalizeQueryString(string  $qs) : 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

string $qs

Query string

Returns

string —

A normalized query string for the Request

static
Inherited from
SymfonyComponentHttpFoundationRequest

Tags

None found

enableHttpMethodParameterOverride()

enableHttpMethodParameterOverride() 

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

Be warned that enabling this feature might lead to CSRF issues in your code. Check that you are using CSRF tokens when required.

The HTTP method can only be overridden when the real HTTP method is POST.

static
Inherited from
SymfonyComponentHttpFoundationRequest

Tags

None found

getHttpMethodParameterOverride()

getHttpMethodParameterOverride() : Boolean

Checks whether support for the _method request parameter is enabled.

Returns

Boolean —

True when the _method request parameter is enabled, false otherwise

static
Inherited from
SymfonyComponentHttpFoundationRequest

Tags

None found

get()

get(string  $key, mixed  $default = null, Boolean  $deep = false) : mixed

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

string $key

the key

mixed $default

the default value

Boolean $deep

is parameter deep in multidimensional array

Returns

mixed

Inherited from
SymfonyComponentHttpFoundationRequest

Tags

None found

getSession()

getSession() : \Symfony\Component\HttpFoundation\Session\SessionInterface|null

Gets the Session.

Returns

SymfonyComponentHttpFoundationSessionSessionInterface|null —

The session

hasPreviousSession()

hasPreviousSession() : Boolean

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

Returns

Boolean

hasSession()

hasSession() : Boolean

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

setSession()

setSession(\Symfony\Component\HttpFoundation\Session\SessionInterface  $session) 

Sets the Session.

Parameters

SymfonyComponentHttpFoundationSessionSessionInterface $session

The Session

getClientIp()

getClientIp() : string

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

Inherited from
SymfonyComponentHttpFoundationRequest
See also

Tags

api

getScriptName()

getScriptName() : string

Returns current script name.

Returns

string

getPathInfo()

getPathInfo() : string

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:

Returns

string —

The raw path (i.e. not urldecoded)

getBasePath()

getBasePath() : string

Returns the root path from which this request is executed.

Suppose that an index.php file instantiates this request object:

Returns

string —

The raw path (i.e. not urldecoded)

getBaseUrl()

getBaseUrl() : string

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)

getScheme()

getScheme() : string

Gets the request's scheme.

Returns

string

getPort()

getPort() : string

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

getUser()

getUser() : string|null

Returns the user.

Returns

string|null

Inherited from
SymfonyComponentHttpFoundationRequest

Tags

None found

getPassword()

getPassword() : string|null

Returns the password.

Returns

string|null

Inherited from
SymfonyComponentHttpFoundationRequest

Tags

None found

getUserInfo()

getUserInfo() : string

Gets the user info.

Returns

string —

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

Inherited from
SymfonyComponentHttpFoundationRequest

Tags

None found

getHttpHost()

getHttpHost() : string

Returns the HTTP host being requested.

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

Returns

string

getRequestUri()

getRequestUri() : string

Returns the requested URI.

Returns

string —

The raw URI (i.e. not urldecoded)

getSchemeAndHttpHost()

getSchemeAndHttpHost() : string

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

Inherited from
SymfonyComponentHttpFoundationRequest

Tags

None found

getUri()

getUri() : string

Generates a normalized URI for the Request.

Returns

string —

A normalized URI for the Request

Inherited from
SymfonyComponentHttpFoundationRequest
See also

Tags

api

getUriForPath()

getUriForPath(string  $path) : string

Generates a normalized URI for the given path.

Parameters

string $path

A path to use instead of the current one

Returns

string —

The normalized URI for the path

getQueryString()

getQueryString() : string|null

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

isSecure()

isSecure() : Boolean

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

getHost()

getHost() : string

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.

Throws

UnexpectedValueException

when the host name is invalid

Returns

string

setMethod()

setMethod(string  $method) 

Sets the request method.

Parameters

string $method

getMethod()

getMethod() : string

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

Inherited from
SymfonyComponentHttpFoundationRequest
See also

Tags

api

getRealMethod()

getRealMethod() : string

Gets the "real" request method.

Returns

string —

The request method

Inherited from
SymfonyComponentHttpFoundationRequest
See also

Tags

None found

getMimeType()

getMimeType(string  $format) : string

Gets the mime type associated with the format.

Parameters

string $format

The format

Returns

string —

The associated mime type (null if not found)

getFormat()

getFormat(string  $mimeType) : string|null

Gets the format associated with the mime type.

Parameters

string $mimeType

The associated mime type

Returns

string|null —

The format (null if not found)

setFormat()

setFormat(string  $format, string|array  $mimeTypes) 

Associates a format with mime types.

Parameters

string $format

The format

string|array $mimeTypes

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

getRequestFormat()

getRequestFormat(string  $default = 'html') : string

Gets the request format.

Here is the process to determine the format:

  • format defined by the user (with setRequestFormat())
  • _format request parameter
  • $default

Parameters

string $default

The default format

Returns

string —

The request format

setRequestFormat()

setRequestFormat(string  $format) 

Sets the request format.

Parameters

string $format

The request format.

getContentType()

getContentType() : string|null

Gets the format associated with the request.

Returns

string|null —

The format (null if no content type is present)

setDefaultLocale()

setDefaultLocale(string  $locale) 

Sets the default locale.

Parameters

string $locale

setLocale()

setLocale(string  $locale) 

Sets the locale.

Parameters

string $locale

getLocale()

getLocale() : string

Get the locale.

Returns

string

Inherited from
SymfonyComponentHttpFoundationRequest

Tags

None found

isMethod()

isMethod(string  $method) : Boolean

Checks if the request method is of specified type.

Parameters

string $method

Uppercase request method (GET, POST etc).

Returns

Boolean

Inherited from
SymfonyComponentHttpFoundationRequest

Tags

None found

isMethodSafe()

isMethodSafe() : Boolean

Checks whether the method is safe or not.

Returns

Boolean

getContent()

getContent(Boolean  $asResource = false) : string|resource

Returns the request body content.

Parameters

Boolean $asResource

If true, a resource will be returned

Throws

LogicException

Returns

string|resource —

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

Inherited from
SymfonyComponentHttpFoundationRequest

Tags

None found

getETags()

getETags() : array

Gets the Etags.

Returns

array —

The entity tags

Inherited from
SymfonyComponentHttpFoundationRequest

Tags

None found

isNoCache()

isNoCache() : Boolean

Returns

Boolean

Inherited from
SymfonyComponentHttpFoundationRequest

Tags

None found

getPreferredLanguage()

getPreferredLanguage(array  $locales = null) : string|null

Returns the preferred language.

Parameters

array $locales

An array of ordered available locales

Returns

string|null —

The preferred locale

getLanguages()

getLanguages() : array

Gets a list of languages acceptable by the client browser.

Returns

array —

Languages ordered in the user browser preferences

getCharsets()

getCharsets() : array

Gets a list of charsets acceptable by the client browser.

Returns

array —

List of charsets in preferable order

getAcceptableContentTypes()

getAcceptableContentTypes() : array

Gets a list of content types acceptable by the client browser

Returns

array —

List of content types in preferable order

isXmlHttpRequest()

isXmlHttpRequest() : Boolean

Returns true if the request is a XMLHttpRequest.

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

Returns

Boolean —

true if the request is an XMLHttpRequest, false otherwise

splitHttpAcceptHeader()

splitHttpAcceptHeader(string  $header) : array

Splits an Accept-* HTTP header.

Parameters

string $header

Header to split

Returns

array —

Array indexed by the values of the Accept-* header in preferred order

Deprecated

Deprecated since version 2.2, to be removed in 2.3.
Inherited from
SymfonyComponentHttpFoundationRequest

Tags

None found

getRootUrl()

getRootUrl() : string

Get the root URL of the application.

Returns

string

Tags

None found

prepareRequestUri()

prepareRequestUri() 

Inherited from
SymfonyComponentHttpFoundationRequest

Tags

None found

prepareBaseUrl()

prepareBaseUrl() : string

Prepares the base URL.

Returns

string

Inherited from
SymfonyComponentHttpFoundationRequest

Tags

None found

prepareBasePath()

prepareBasePath() : string

Prepares the base path.

Returns

string —

base path

Inherited from
SymfonyComponentHttpFoundationRequest

Tags

None found

preparePathInfo()

preparePathInfo() : string

Prepares the path info.

Returns

string —

path info

Inherited from
SymfonyComponentHttpFoundationRequest

Tags

None found

initializeFormats()

initializeFormats() 

Initializes HTTP request formats.

static
Inherited from
SymfonyComponentHttpFoundationRequest

Tags

None found

setPhpDefaultLocale()

setPhpDefaultLocale(string  $locale) 

Sets the default PHP locale.

Parameters

string $locale

Inherited from
SymfonyComponentHttpFoundationRequest

Tags

None found

getUrlencodedPrefix()

getUrlencodedPrefix(  $string,   $prefix) 

Parameters

$string
$prefix

Inherited from
SymfonyComponentHttpFoundationRequest

Tags

None found