# Request

class Request extends Request implements Request

Request Class and Interface Implement

## Constants

`HEADER_FORWARDED = 0b00001; // When using RFC 7239` |
`HEADER_X_FORWARDED_FOR = 0b00010;` |
`HEADER_X_FORWARDED_HOST = 0b00100;` |
`HEADER_X_FORWARDED_PROTO = 0b01000;` |
`HEADER_X_FORWARDED_PORT = 0b10000;` |
`HEADER_X_FORWARDED_ALL = 0b11110; // All "X-Forwarded-*" headers` |
`HEADER_X_FORWARDED_AWS_ELB = 0b11010; // AWS ELB doesn't send X-Forwarded-Host` |
`METHOD_HEAD = 'HEAD';` |
`METHOD_GET = 'GET';` |
`METHOD_POST = 'POST';` |
`METHOD_PUT = 'PUT';` |
`METHOD_PATCH = 'PATCH';` |
`METHOD_DELETE = 'DELETE';` |
`METHOD_PURGE = 'PURGE';` |
`METHOD_OPTIONS = 'OPTIONS';` |
`METHOD_TRACE = 'TRACE';` |
`METHOD_CONNECT = 'CONNECT';` |

## Properties

`static protected string[]` | `$trustedProxies` |  | from Request
`static protected string[]` | `$trustedHostPatterns` |  | from Request
`static protected string[]` | `$trustedHosts` |  | from Request
`static protected` | `$httpMethodParameterOverride` |  | from Request
`ParameterBag` | `$attributes` | Custom parameters. | from Request
`ParameterBag` | `$request` | Request body parameters ($_POST). | from Request
`ParameterBag` | `$query` | Query string parameters ($_GET). | from Request
`ServerBag` | `$server` | Server and execution environment parameters ($_SERVER). | from Request
`FileBag` | `$files` | Uploaded files ($_FILES). | from Request
`ParameterBag` | `$cookies` | Cookies ($_COOKIE). | from Request
`HeaderBag` | `$headers` | Headers (taken from the $_SERVER). | from Request
`protected string|resource|false|null` | `$content` |  | from Request
`protected array` | `$languages` |  | from Request
`protected array` | `$charsets` |  | from Request
`protected array` | `$encodings` |  | from Request
`protected array` | `$acceptableContentTypes` |  | from Request
`protected string` | `$pathInfo` |  | from Request
`protected string` | `$requestUri` |  | from Request
`protected string` | `$baseUrl` |  | from Request
`protected string` | `$basePath` |  | from Request
`protected string` | `$method` |  | from Request
`protected string` | `$format` |  | from Request
`protected SessionInterface` | `$session` |  | from Request
`protected string` | `$locale` |  | from Request
`protected string` | `$defaultLocale` |  | from Request
`static protected array` | `$formats` |  | from Request
`static protected` | `$requestFactory` |  | from Request

## Methods

`public` | `` | `__construct(array $reqs = array(), $uri = '')` | No description |
`public` | `` | `initialize(array $query = array(), array $request = array(), array $attributes = array(), array $cookies = array(), array $files = array(), array $server = array(), string|resource|null $content = null)` | Sets the parameters for this request. | from Request
`public static` | `Request` | `createFromGlobals()` | Creates a new request with values from PHP's super globals. | from Request
`public static` | `Request` | `create(string $uri, string $method = 'GET', array $parameters = array(), array $cookies = array(), array $files = array(), array $server = array(), string|resource|null $content = null)` | Creates a Request based on a given URI and configuration. | from Request
`public static` | `` | `setFactory(callable|null $callable)` | Sets a callable able to create a Request instance. | from Request
`public` | `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. | from Request
`public` | `` | `__clone()` | Clones the current request. | from Request
`public` | `string` | `__toString()` | Returns the request as a string. | from Request
`public` | `` | `overrideGlobals()` | Overrides the PHP global variables according to this request instance. | from Request
`public static` | `` | `setTrustedProxies(array $proxies, int $trustedHeaderSet)` | Sets a list of trusted proxies. | from Request
`public static` | `array` | `getTrustedProxies()` | Gets the list of trusted proxies. | from Request
`public static` | `int` | `getTrustedHeaderSet()` | Gets the set of trusted headers from trusted proxies. | from Request
`public static` | `` | `setTrustedHosts(array $hostPatterns)` | Sets a list of trusted host patterns. | from Request
`public static` | `array` | `getTrustedHosts()` | Gets the list of trusted host patterns. | from Request
`public static` | `string` | `normalizeQueryString(string $qs)` | Normalizes a query string. | from Request
`public static` | `` | `enableHttpMethodParameterOverride()` | Enables support for the _method request parameter to determine the intended HTTP method. | from Request
`public static` | `bool` | `getHttpMethodParameterOverride()` | Checks whether support for the _method request parameter is enabled. | from Request
`public` | `mixed` | `get(string $key, mixed $default = null)` | Gets a "parameter" value from any bag. | from Request
`public` | `SessionInterface|null` | `getSession()` | Gets the Session. | from Request
`public` | `bool` | `hasPreviousSession()` | Whether the request contains a Session which was started in one of the previous requests. | from Request
`public` | `bool` | `hasSession()` | Whether the request contains a Session object. | from Request
`public` | `` | `setSession(SessionInterface $session)` | Sets the Session. | from Request
`public` | `` | `setSessionFactory(callable $factory)` | No description | from Request
`public` | `array` | `getClientIps()` | Returns the client IP addresses. | from Request
`public` | `string|null` | `getClientIp()` | Returns the client IP address. | from Request
`public` | `string` | `getScriptName()` | Returns current script name. | from Request
`public` | `string` | `getPathInfo()` | Returns the path being requested relative to the executed script. | from Request
`public` | `string` | `getBasePath()` | Returns the root path from which this request is executed. | from Request
`public` | `string` | `getBaseUrl()` | Returns the root URL from which this request is executed. | from Request
`public` | `string` | `getScheme()` | Gets the request's scheme. | from Request
`public` | `int|string` | `getPort()` | Returns the port on which the request is made. | from Request
`public` | `string|null` | `getUser()` | Returns the user. | from Request
`public` | `string|null` | `getPassword()` | Returns the password. | from Request
`public` | `string` | `getUserInfo()` | Gets the user info. | from Request
`public` | `string` | `getHttpHost()` | Returns the HTTP host being requested. | from Request
`public` | `string` | `getRequestUri()` | Returns the requested URI (path and query string). | from Request
`public` | `string` | `getSchemeAndHttpHost()` | Gets the scheme and HTTP host. | from Request
`public` | `string` | `getUri()` | Generates a normalized URI (URL) for the Request. | from Request
`public` | `string` | `getUriForPath(string $path)` | Generates a normalized URI for the given path. | from Request
`public` | `string` | `getRelativeUriForPath(string $path)` | Returns the path as relative reference from the current Request path. | from Request
`public` | `string|null` | `getQueryString()` | Generates the normalized query string for the Request. | from Request
`public` | `bool` | `isSecure()` | Checks whether the request is secure or not. | from Request
`public` | `string` | `getHost()` | Returns the host name. | from Request
`public` | `` | `setMethod(string $method)` | Sets the request method. | from Request
`public` | `string` | `getMethod()` | Gets the request "intended" method. | from Request
`public` | `string` | `getRealMethod()` | Gets the "real" request method. | from Request
`public` | `string` | `getMimeType(string $format)` | Gets the mime type associated with the format. | from Request
`public static` | `array` | `getMimeTypes(string $format)` | Gets the mime types associated with the format. | from Request
`public` | `string|null` | `getFormat(string $mimeType)` | Gets the format associated with the mime type. | from Request
`public` | `` | `setFormat(string $format, string|array $mimeTypes)` | Associates a format with mime types. | from Request
`public` | `string` | `getRequestFormat(string $default = 'html')` | Gets the request format. | from Request
`public` | `` | `setRequestFormat(string $format)` | Sets the request format. | from Request
`public` | `string|null` | `getContentType()` | Gets the format associated with the request. | from Request
`public` | `` | `setDefaultLocale(string $locale)` | Sets the default locale. | from Request
`public` | `string` | `getDefaultLocale()` | Get the default locale. | from Request
`public` | `` | `setLocale(string $locale)` | Sets the locale. | from Request
`public` | `string` | `getLocale()` | Get the locale. | from Request
`public` | `bool` | `isMethod(string $method)` | Checks if the request method is of specified type. | from Request
`public` | `bool` | `isMethodSafe()` | Checks whether or not the method is safe. | from Request
`public` | `bool` | `isMethodIdempotent()` | Checks whether or not the method is idempotent. | from Request
`public` | `bool` | `isMethodCacheable()` | Checks whether the method is cacheable or not. | from Request
`public` | `string` | `getProtocolVersion()` | Returns the protocol version. | from Request
`public` | `string|resource` | `getContent(bool $asResource = false)` | Returns the request body content. | from Request
`public` | `array` | `getETags()` | Gets the Etags. | from Request
`public` | `bool` | `isNoCache()` | No description | from Request
`public` | `string|null` | `getPreferredLanguage(array $locales = null)` | Returns the preferred language. | from Request
`public` | `array` | `getLanguages()` | Gets a list of languages acceptable by the client browser. | from Request
`public` | `array` | `getCharsets()` | Gets a list of charsets acceptable by the client browser. | from Request
`public` | `array` | `getEncodings()` | Gets a list of encodings acceptable by the client browser. | from Request
`public` | `array` | `getAcceptableContentTypes()` | Gets a list of content types acceptable by the client browser. | from Request
`public` | `bool` | `isXmlHttpRequest()` | Returns true if the request is a XMLHttpRequest. | from Request
`protected` | `` | `prepareRequestUri()` | No description | from Request
`protected` | `string` | `prepareBaseUrl()` | Prepares the base URL. | from Request
`protected` | `string` | `prepareBasePath()` | Prepares the base path. | from Request
`protected` | `string` | `preparePathInfo()` | Prepares the path info. | from Request
`protected static` | `` | `initializeFormats()` | Initializes HTTP request formats. | from Request
`public` | `bool` | `isFromTrustedProxy()` | Indicates whether this request originated from a trusted proxy. | from Request
`public` | `` | `infoFile($data)` | No description |
`public` | `` | `makeRequests()` | No description |
`public static` | `` | `getAll()` | No description |
`public static` | `` | `make($name = null, $key, $value)` | No description |
`public static` | `` | `validateValue($type, $value)` | No description |
`public static` | `` | `validateType($type, $value)` | No description |
`public static` | `` | `post($name = null)` | No description |
`public static` | `` | `files($name = null)` | No description |
`public static` | `` | `put($name = null)` | No description |
`public static` | `` | `delete($name = null)` | No description |
`public static` | `` | `params($name = null)` | No description |
`public static` | `` | `session($name = null)` | No description |

## Details

at line 15

### `__construct()`

`public __construct(array $reqs = array(), $uri = '')`

#### Parameters

`array` | `$reqs` |
| `$uri` |

in Request at line 251

### `initialize()`

`public initialize(array $query = array(), array $request = array(), array $attributes = array(), array $cookies = array(), array $files = array(), array $server = array(), string|resource|null $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|resource|null` | `$content` | The raw body data

in Request at line 279

### `createFromGlobals()`

`public static Request createFromGlobals()`

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

#### Return Value

`Request` |

in Request at line 309

### `create()`

`public static Request create(string $uri, string $method = 'GET', array $parameters = array(), array $cookies = array(), array $files = array(), array $server = array(), string|resource|null $content = null)`

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|resource|null` | `$content` | The raw body data

#### Return Value

`Request` |

in Request at line 410

### `setFactory()`

`public static setFactory(callable|null $callable)`

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

in Request at line 427

### `duplicate()`

`public 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.

#### 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

#### Return Value

`Request` |

in Request at line 477

### `__clone()`

`public __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.

in Request at line 493

### `__toString()`

`public string __toString()`

Returns the request as a string.

#### Return Value

`string` | The request

in Request at line 525

### `overrideGlobals()`

`public overrideGlobals()`

Overrides the PHP global variables according to this request instance.

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

in Request at line 564

### `setTrustedProxies()`

`public static setTrustedProxies(array $proxies, int $trustedHeaderSet)`

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
`int` | `$trustedHeaderSet` | A bit field of Request::HEADER_*, to set which headers to trust from your proxies

#### Exceptions

InvalidArgumentException | When $trustedHeaderSet is invalid

in Request at line 575

### `getTrustedProxies()`

`public static array getTrustedProxies()`

Gets the list of trusted proxies.

#### Return Value

`array` | An array of trusted proxies

in Request at line 585

### `getTrustedHeaderSet()`

`public static int getTrustedHeaderSet()`

Gets the set of trusted headers from trusted proxies.

#### Return Value

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

in Request at line 597

### `setTrustedHosts()`

`public static setTrustedHosts(array $hostPatterns)`

Sets a list of trusted host patterns.

You should only list the hosts you manage using regexs.

#### Parameters

`array` | `$hostPatterns` | A list of trusted host patterns

in Request at line 611

### `getTrustedHosts()`

`public static array getTrustedHosts()`

Gets the list of trusted host patterns.

#### Return Value

`array` | An array of trusted host patterns

in Request at line 626

### `normalizeQueryString()`

`public static string normalizeQueryString(string $qs)`

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

#### Return Value

`string` | A normalized query string for the Request

in Request at line 649

### `enableHttpMethodParameterOverride()`

`public static 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. 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.

in Request at line 659

### `getHttpMethodParameterOverride()`

`public static bool getHttpMethodParameterOverride()`

Checks whether support for the _method request parameter is enabled.

#### Return Value

`bool` | True when the _method request parameter is enabled, false otherwise

in Request at line 678

### `get()`

`public mixed get(string $key, mixed $default = null)`

Gets a "parameter" value from any bag.

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

`string` | `$key` | The key
`mixed` | `$default` | The default value if the parameter key does not exist

#### Return Value

`mixed` |

in Request at line 700

### `getSession()`

`public SessionInterface|null getSession()`

Gets the Session.

#### Return Value

`SessionInterface|null` | The session

in Request at line 721

### `hasPreviousSession()`

`public bool hasPreviousSession()`

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

#### Return Value

`bool` |

in Request at line 736

### `hasSession()`

`public bool hasSession()`

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.

#### Return Value

`bool` | true when the Request contains a Session object, false otherwise

in Request at line 746

### `setSession()`

`public setSession(SessionInterface $session)`

Sets the Session.

#### Parameters

`SessionInterface` | `$session` | The Session

in Request at line 754

### `setSessionFactory()`

`public setSessionFactory(callable $factory)`

#### Parameters

`callable` | `$factory` |

in Request at line 772

### `getClientIps()`

`public array getClientIps()`

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.

#### Return Value

`array` | The client IP addresses

#### See also

getClientIp() |

in Request at line 797

### `getClientIp()`

`public string|null getClientIp()`

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.

#### Return Value

`string|null` | The client IP address

#### See also

getClientIps() |
http://en.wikipedia.org/wiki/X-Forwarded-For |

in Request at line 809

### `getScriptName()`

`public string getScriptName()`

Returns current script name.

#### Return Value

`string` |

in Request at line 828

### `getPathInfo()`

`public string getPathInfo()`

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'

#### Return Value

`string` | The raw path (i.e. not urldecoded)

in Request at line 849

### `getBasePath()`

`public string getBasePath()`

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'

#### Return Value

`string` | The raw path (i.e. not urldecoded)

in Request at line 868

### `getBaseUrl()`

`public string getBaseUrl()`

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.

#### Return Value

`string` | The raw URL (i.e. not urldecoded)

in Request at line 882

### `getScheme()`

`public string getScheme()`

Gets the request's scheme.

#### Return Value

`string` |

in Request at line 897

### `getPort()`

`public int|string getPort()`

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.

#### Return Value

`int|string` | can be a string if fetched from the server bag

in Request at line 925

### `getUser()`

`public string|null getUser()`

Returns the user.

#### Return Value

`string|null` |

in Request at line 935

### `getPassword()`

`public string|null getPassword()`

Returns the password.

#### Return Value

`string|null` |

in Request at line 945

### `getUserInfo()`

`public string getUserInfo()`

Gets the user info.

#### Return Value

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

in Request at line 964

### `getHttpHost()`

`public string getHttpHost()`

Returns the HTTP host being requested.

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

#### Return Value

`string` |

in Request at line 981

### `getRequestUri()`

`public string getRequestUri()`

Returns the requested URI (path and query string).

#### Return Value

`string` | The raw URI (i.e. not URI decoded)

in Request at line 998

### `getSchemeAndHttpHost()`

`public string getSchemeAndHttpHost()`

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.

#### Return Value

`string` | The scheme and HTTP host

in Request at line 1010

### `getUri()`

`public string getUri()`

Generates a normalized URI (URL) for the Request.

#### Return Value

`string` | A normalized URI (URL) for the Request

#### See also

getQueryString() |

in Request at line 1026

### `getUriForPath()`

`public string getUriForPath(string $path)`

Generates a normalized URI for the given path.

#### Parameters

`string` | `$path` | A path to use instead of the current one

#### Return Value

`string` | The normalized URI for the path

in Request at line 1050

### `getRelativeUriForPath()`

`public string getRelativeUriForPath(string $path)`

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

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

`string` | `$path` | The target path

#### Return Value

`string` | The relative target path

in Request at line 1094

### `getQueryString()`

`public string|null getQueryString()`

Generates the normalized query string for the Request.

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

#### Return Value

`string|null` | A normalized query string for the Request

in Request at line 1111

### `isSecure()`

`public bool isSecure()`

Checks whether the request is secure or not.

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 Value

`bool` |

in Request at line 1134

### `getHost()`

`public string getHost()`

Returns the host name.

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.

#### Return Value

`string` |

#### Exceptions

SuspiciousOperationException | when the host name is invalid or not trusted

in Request at line 1191

### `setMethod()`

`public setMethod(string $method)`

Sets the request method.

#### Parameters

`string` | `$method` |

in Request at line 1212

### `getMethod()`

`public string getMethod()`

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.

#### Return Value

`string` | The request method

#### See also

getRealMethod() |

in Request at line 1236

### `getRealMethod()`

`public string getRealMethod()`

Gets the "real" request method.

#### Return Value

`string` | The request method

#### See also

getMethod() |

in Request at line 1248

### `getMimeType()`

`public string getMimeType(string $format)`

Gets the mime type associated with the format.

#### Parameters

`string` | `$format` | The format

#### Return Value

`string` | The associated mime type (null if not found)

in Request at line 1264

### `getMimeTypes()`

`public static array getMimeTypes(string $format)`

Gets the mime types associated with the format.

#### Parameters

`string` | `$format` | The format

#### Return Value

`array` | The associated mime types

in Request at line 1280

### `getFormat()`

`public string|null getFormat(string $mimeType)`

Gets the format associated with the mime type.

#### Parameters

`string` | `$mimeType` | The associated mime type

#### Return Value

`string|null` | The format (null if not found)

in Request at line 1307

### `setFormat()`

`public 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)

in Request at line 1329

### `getRequestFormat()`

`public string getRequestFormat(string $default = 'html')`

Gets the request format.

Here is the process to determine the format:

- format defined by the user (with setRequestFormat())
- _format request attribute
- $default

#### Parameters

`string` | `$default` | The default format

#### Return Value

`string` | The request format

in Request at line 1343

### `setRequestFormat()`

`public setRequestFormat(string $format)`

Sets the request format.

#### Parameters

`string` | `$format` | The request format

in Request at line 1353

### `getContentType()`

`public string|null getContentType()`

Gets the format associated with the request.

#### Return Value

`string|null` | The format (null if no content type is present)

in Request at line 1363

### `setDefaultLocale()`

`public setDefaultLocale(string $locale)`

Sets the default locale.

#### Parameters

`string` | `$locale` |

in Request at line 1377

### `getDefaultLocale()`

`public string getDefaultLocale()`

Get the default locale.

#### Return Value

`string` |

in Request at line 1387

### `setLocale()`

`public setLocale(string $locale)`

Sets the locale.

#### Parameters

`string` | `$locale` |

in Request at line 1397

### `getLocale()`

`public string getLocale()`

Get the locale.

#### Return Value

`string` |

in Request at line 1409

### `isMethod()`

`public bool isMethod(string $method)`

Checks if the request method is of specified type.

#### Parameters

`string` | `$method` | Uppercase request method (GET, POST etc)

#### Return Value

`bool` |

in Request at line 1423

### `isMethodSafe()`

`public bool isMethodSafe()`

Checks whether or not the method is safe.

#### Return Value

`bool` |

#### See also

https://tools.ietf.org/html/rfc7231#section-4.2.1 |

in Request at line 1438

### `isMethodIdempotent()`

`public bool isMethodIdempotent()`

Checks whether or not the method is idempotent.

#### Return Value

`bool` |

in Request at line 1450

### `isMethodCacheable()`

`public bool isMethodCacheable()`

Checks whether the method is cacheable or not.

#### Return Value

`bool` |

#### See also

https://tools.ietf.org/html/rfc7231#section-4.2.3 |

in Request at line 1466

### `getProtocolVersion()`

`public string getProtocolVersion()`

Returns the protocol version.

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 Value

`string` |

in Request at line 1488

### `getContent()`

`public string|resource getContent(bool $asResource = false)`

Returns the request body content.

#### Parameters

`bool` | `$asResource` | If true, a resource will be returned

#### Return Value

`string|resource` | The request body content or a resource to read the body stream

#### Exceptions

LogicException |

in Request at line 1531

### `getETags()`

`public array getETags()`

Gets the Etags.

#### Return Value

`array` | The entity tags

in Request at line 1539

### `isNoCache()`

`public bool isNoCache()`

#### Return Value

`bool` |

in Request at line 1551

### `getPreferredLanguage()`

`public string|null getPreferredLanguage(array $locales = null)`

Returns the preferred language.

#### Parameters

`array` | `$locales` | An array of ordered available locales

#### Return Value

`string|null` | The preferred locale

in Request at line 1584

### `getLanguages()`

`public array getLanguages()`

Gets a list of languages acceptable by the client browser.

#### Return Value

`array` | Languages ordered in the user browser preferences

in Request at line 1624

### `getCharsets()`

`public array getCharsets()`

Gets a list of charsets acceptable by the client browser.

#### Return Value

`array` | List of charsets in preferable order

in Request at line 1638

### `getEncodings()`

`public array getEncodings()`

Gets a list of encodings acceptable by the client browser.

#### Return Value

`array` | List of encodings in preferable order

in Request at line 1652

### `getAcceptableContentTypes()`

`public array getAcceptableContentTypes()`

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

#### Return Value

`array` | List of content types in preferable order

in Request at line 1671

### `isXmlHttpRequest()`

`public bool isXmlHttpRequest()`

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:

#### Return Value

`bool` | true if the request is an XMLHttpRequest, false otherwise

#### See also

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

in Request at line 1684

### `prepareRequestUri()`

`protected prepareRequestUri()`
in Request at line 1731

### `prepareBaseUrl()`

`protected string prepareBaseUrl()`

Prepares the base URL.

#### Return Value

`string` |

in Request at line 1800

### `prepareBasePath()`

`protected string prepareBasePath()`

Prepares the base path.

#### Return Value

`string` | base path

in Request at line 1826

### `preparePathInfo()`

`protected string preparePathInfo()`

Prepares the path info.

#### Return Value

`string` | path info

in Request at line 1856

### `initializeFormats()`

`protected static initializeFormats()`

Initializes HTTP request formats.

in Request at line 1930

### `isFromTrustedProxy()`

`public bool isFromTrustedProxy()`

Indicates whether this request originated from a trusted proxy.

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

#### Return Value

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

at line 23

### `infoFile()`

`public infoFile($data)`

#### Parameters

| `$data` |

at line 34

### `makeRequests()`

`public makeRequests()`
at line 44

### `getAll()`

`public static getAll()`
at line 48

### `make()`

`public static make($name = null, $key, $value)`

#### Parameters

| `$name` |
| `$key` |
| `$value` |

at line 52

### `validateValue()`

`public static validateValue($type, $value)`

#### Parameters

| `$type` |
| `$value` |

at line 56

### `validateType()`

`public static validateType($type, $value)`

#### Parameters

| `$type` |
| `$value` |

at line 64

### `post()`

`public static post($name = null)`

#### Parameters

| `$name` |

at line 75

### `files()`

`public static files($name = null)`

#### Parameters

| `$name` |

at line 86

### `put()`

`public static put($name = null)`

#### Parameters

| `$name` |

at line 97

### `delete()`

`public static delete($name = null)`

#### Parameters

| `$name` |

at line 108

### `params()`

`public static params($name = null)`

#### Parameters

| `$name` |

at line 119

### `session()`

`public static session($name = null)`

#### Parameters

| `$name` |

## Source code

    <?php

    	namespace App\Khan\Component\Router\Http;
      use \App\Khan\Component\HttpFoundation\Request as RequestFoundation;
      use \App\Khan\Component\Router\Http\Interfaces\Request as RequestInterface;

    	/**
    	* Request Class and Interface Implement
    	*/

    	class Request extends RequestFoundation implements RequestInterface{

        private static $data = [];

          public function __construct(Array $reqs = array(), $uri = ''){
            $this->makeRequests();
            parent::__construct($_GET, $_POST, array(), $_COOKIE, $_FILES, $_SERVER);
            self::$data = $this->infoFile($reqs);
            $this->current_uri = $uri;
            $this->class_name = __CLASS__;
          }

          public function infoFile($data){
            foreach ($data['files'] as $key => $file) {
              $ext = pathinfo($file['name'], PATHINFO_EXTENSION);
              $data["files"][$key]["ext"] = $ext;
              $data["files"][$key]["newName"] = function($name) use($ext){
                 return $name.".".$ext;
              };
            }
            return $data;
          }

          public function makeRequests(){
            if(is_null($_GET)): $_GET = []; endif;
            if(is_null($_POST)): $_POST = []; endif;
            if(isset($_PUT) && is_null($_PUT)): $_PUT = []; endif;
            if(isset($_DELETE) && is_null($_DELETE)): $_DELETE = []; endif;
            if(is_null($_SERVER)): $_SERVER = []; endif;
            if(is_null($_COOKIE)): $_COOKIE = []; endif;
            if(is_null($_FILES)): $_FILES = []; endif;
          }

          public static function getAll(){
              return self::$data;
          }

          public static function make($name = null, $key, $value){
              self::$data[$name][$key] = $value;
          }

          public static function validateValue($type, $value){
            return in_array($value, self::$data[$type]);
          }

          public static function validateType($type, $value){
            $retorno = '';
            if(in_array($type, self::$data)){
              $retorno = Request::validateValue($type, $value);
            }
            return $retorno;
          }

          public static function post($name = null){
            $validate = Request::validateValue("post", $name);
            if($validate && $name !== null){ return false; }
            if($name == null){
              return self::$data["post"];
            }else{
              return self::$data["post"][$name];
            }
            return false;
          }

          public static function files($name = null){
            $validate = Request::validateValue("files", $name);
            if($validate && $name !== null){ return false; }
            if($name == null){
              return self::$data["files"];
            }else{
              return self::$data["files"][$name];
            }
            return false;
          }

          public static function put($name = null){
            $validate = Request::validateValue("put", $name);
            if($validate && $name !== null){ return false; }
            if($name == null){
              return self::$data["put"];
            }else{
              return self::$data["put"][$name];
            }
            return false;
          }

          public static function delete($name = null){
            $validate = Request::validateValue("delete", $name);
            if($validate && $name !== null){ return false; }
            if($name == null){
              return self::$data["delete"];
            }else{
              return self::$data["delete"][$name];
            }
            return false;
          }

          public static function params($name = null){
            $validate = Request::validateValue("params", $name);
            if($validate && $name !== null){ return false; }
            if($name == null){
              return self::$data["params"];
            }else{
              return self::$data["params"][$name];
            }
            return false;
          }

          public static function session($name = null){
            $validate = Request::validateValue("session", $name);
            if($validate && $name !== null){ return false; }
            if($name == null){
              return self::$data["session"];
            }else{
              return self::$data["session"][$name];
            }
            return false;
          }

    	}