class ApacheRequest extends Request
Request represents an HTTP request from an Apache server.
HEADER_FORWARDED | |
HEADER_X_FORWARDED_FOR | |
HEADER_X_FORWARDED_HOST | |
HEADER_X_FORWARDED_PROTO | |
HEADER_X_FORWARDED_PORT | |
HEADER_X_FORWARDED_ALL | |
HEADER_X_FORWARDED_AWS_ELB | |
METHOD_HEAD | |
METHOD_GET | |
METHOD_POST | |
METHOD_PUT | |
METHOD_PATCH | |
METHOD_DELETE | |
METHOD_PURGE | |
METHOD_OPTIONS | |
METHOD_TRACE | |
METHOD_CONNECT |
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 |
__construct(array $query = array(), array $request = array(), array $attributes = array(), array $cookies = array(), array $files = array(), array $server = array(), string|resource|null $content = null) | from Request | |
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 | |
static Request | createFromGlobals() Creates a new request with values from PHP's super globals. | from Request |
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 |
static | setFactory(callable|null $callable) Sets a callable able to create a Request instance. | from Request |
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 |
__clone() Clones the current request. | from Request | |
string | __toString() Returns the request as a string. | from Request |
overrideGlobals() Overrides the PHP global variables according to this request instance. | from Request | |
static | setTrustedProxies(array $proxies, int $trustedHeaderSet) Sets a list of trusted proxies. | from Request |
static array | getTrustedProxies() Gets the list of trusted proxies. | from Request |
static int | getTrustedHeaderSet() Gets the set of trusted headers from trusted proxies. | from Request |
static | setTrustedHosts(array $hostPatterns) Sets a list of trusted host patterns. | from Request |
static array | getTrustedHosts() Gets the list of trusted host patterns. | from Request |
static string | normalizeQueryString(string $qs) Normalizes a query string. | from Request |
static | enableHttpMethodParameterOverride() Enables support for the _method request parameter to determine the intended HTTP method. | from Request |
static bool | getHttpMethodParameterOverride() Checks whether support for the _method request parameter is enabled. | from Request |
mixed | get(string $key, mixed $default = null) Gets a "parameter" value from any bag. | from Request |
SessionInterface|null | getSession() Gets the Session. | from Request |
bool | hasPreviousSession() Whether the request contains a Session which was started in one of the previous requests. | from Request |
bool | hasSession() Whether the request contains a Session object. | from Request |
setSession(SessionInterface $session) Sets the Session. | from Request | |
setSessionFactory(callable $factory) | from Request | |
array | getClientIps() Returns the client IP addresses. | from Request |
string|null | getClientIp() Returns the client IP address. | from Request |
string | getScriptName() Returns current script name. | from Request |
string | getPathInfo() Returns the path being requested relative to the executed script. | from Request |
string | getBasePath() Returns the root path from which this request is executed. | from Request |
string | getBaseUrl() Returns the root URL from which this request is executed. | from Request |
string | getScheme() Gets the request's scheme. | from Request |
int|string | getPort() Returns the port on which the request is made. | from Request |
string|null | getUser() Returns the user. | from Request |
string|null | getPassword() Returns the password. | from Request |
string | getUserInfo() Gets the user info. | from Request |
string | getHttpHost() Returns the HTTP host being requested. | from Request |
string | getRequestUri() Returns the requested URI (path and query string). | from Request |
string | getSchemeAndHttpHost() Gets the scheme and HTTP host. | from Request |
string | getUri() Generates a normalized URI (URL) for the Request. | from Request |
string | getUriForPath(string $path) Generates a normalized URI for the given path. | from Request |
string | getRelativeUriForPath(string $path) Returns the path as relative reference from the current Request path. | from Request |
string|null | getQueryString() Generates the normalized query string for the Request. | from Request |
bool | isSecure() Checks whether the request is secure or not. | from Request |
string | getHost() Returns the host name. | from Request |
setMethod(string $method) Sets the request method. | from Request | |
string | getMethod() Gets the request "intended" method. | from Request |
string | getRealMethod() Gets the "real" request method. | from Request |
string|null | getMimeType(string $format) Gets the mime type associated with the format. | from Request |
static array | getMimeTypes(string $format) Gets the mime types associated with the format. | from Request |
string|null | getFormat(string $mimeType) Gets the format associated with the mime type. | from Request |
setFormat(string $format, string|array $mimeTypes) Associates a format with mime types. | from Request | |
string | getRequestFormat(string|null $default = 'html') Gets the request format. | from Request |
setRequestFormat(string $format) Sets the request format. | from Request | |
string|null | getContentType() Gets the format associated with the request. | from Request |
setDefaultLocale(string $locale) Sets the default locale. | from Request | |
string | getDefaultLocale() Get the default locale. | from Request |
setLocale(string $locale) Sets the locale. | from Request | |
string | getLocale() Get the locale. | from Request |
bool | isMethod(string $method) Checks if the request method is of specified type. | from Request |
bool | isMethodSafe() Checks whether or not the method is safe. | from Request |
bool | isMethodIdempotent() Checks whether or not the method is idempotent. | from Request |
bool | isMethodCacheable() Checks whether the method is cacheable or not. | from Request |
string | getProtocolVersion() Returns the protocol version. | from Request |
string|resource | getContent(bool $asResource = false) Returns the request body content. | from Request |
array | getETags() Gets the Etags. | from Request |
bool | isNoCache() | from Request |
string|null | getPreferredLanguage(array $locales = null) Returns the preferred language. | from Request |
array | getLanguages() Gets a list of languages acceptable by the client browser. | from Request |
array | getCharsets() Gets a list of charsets acceptable by the client browser. | from Request |
array | getEncodings() Gets a list of encodings acceptable by the client browser. | from Request |
array | getAcceptableContentTypes() Gets a list of content types acceptable by the client browser. | from Request |
bool | isXmlHttpRequest() Returns true if the request is a XMLHttpRequest. | from Request |
prepareRequestUri() | ||
string | prepareBaseUrl() Prepares the base URL. | |
string | prepareBasePath() Prepares the base path. | from Request |
string | preparePathInfo() Prepares the path info. | from Request |
static | initializeFormats() Initializes HTTP request formats. | from Request |
bool | isFromTrustedProxy() Indicates whether this request originated from a trusted proxy. | from Request |
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 |
Sets the parameters for this request.
This method also re-initializes all properties.
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 |
Creates a new request with values from PHP's super globals.
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).
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 |
Request |
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.
callable|null | $callable | A PHP callable |
Clones a request and overrides some of its 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 |
Request |
Clones the current request.
Note that the session is not cloned as duplicated requests are most of the time sub-requests of the main one.
Returns the request as a string.
string | The request |
Overrides the PHP global variables according to this request instance.
It overrides $_GET, $_POST, $_REQUEST, $_SERVER, $_COOKIE. $_FILES is never overridden, see rfc1867
Sets a list of trusted proxies.
You should only list the reverse proxies that you manage directly.
array | $proxies | A list of trusted proxies |
int | $trustedHeaderSet | A bit field of Request::HEADER_*, to set which headers to trust from your proxies |
InvalidArgumentException | When $trustedHeaderSet is invalid |
Gets the list of trusted proxies.
array | An array of trusted proxies |
Gets the set of trusted headers from trusted proxies.
int | A bit field of Request::HEADER_* that defines which headers are trusted from your proxies |
Sets a list of trusted host patterns.
You should only list the hosts you manage using regexs.
array | $hostPatterns | A list of trusted host patterns |
Gets the list of trusted host patterns.
array | An array of trusted host patterns |
Normalizes a query string.
It builds a normalized query string, where keys/value pairs are alphabetized, have consistent escaping and unneeded delimiters are removed.
string | $qs | Query string |
string | A normalized query string for the Request |
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.
Checks whether support for the _method request parameter is enabled.
bool | True when the _method request parameter is enabled, false otherwise |
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
string | $key | The key |
mixed | $default | The default value if the parameter key does not exist |
mixed |
Gets the Session.
SessionInterface|null | The session |
Whether the request contains a Session which was started in one of the previous requests.
bool |
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.
bool | true when the Request contains a Session object, false otherwise |
Sets the Session.
SessionInterface | $session | The Session |
callable | $factory |
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.
array | The client IP addresses |
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.
string|null | The client IP address |
getClientIps() | |
http://en.wikipedia.org/wiki/X-Forwarded-For |
Returns current script name.
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:
string | The raw path (i.e. not urldecoded) |
Returns the root path from which this request is executed.
Suppose that an index.php file instantiates this request object:
string | The raw path (i.e. not urldecoded) |
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.
string | The raw URL (i.e. not urldecoded) |
Gets the request's scheme.
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.
int|string | can be a string if fetched from the server bag |
Returns the user.
string|null |
Returns the password.
string|null |
Gets the user info.
string | A user name and, optionally, scheme-specific information about how to gain authorization to access the server |
Returns the HTTP host being requested.
The port name will be appended to the host if it's non-standard.
string |
Returns the requested URI (path and query string).
string | The raw URI (i.e. not URI decoded) |
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.
string | The scheme and HTTP host |
Generates a normalized URI (URL) for the Request.
string | A normalized URI (URL) for the Request |
getQueryString() |
Generates a normalized URI for the given path.
string | $path | A path to use instead of the current one |
string | The normalized URI for the 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"
string | $path | The target path |
string | The relative target path |
Generates the normalized query string for the Request.
It builds a normalized query string, where keys/value pairs are alphabetized and have consistent escaping.
string|null | A normalized query string for the Request |
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".
bool |
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.
string |
SuspiciousOperationException | when the host name is invalid or not trusted |
Sets the request method.
string | $method |
Gets the request "intended" method.
If the X-HTTP-Method-Override header is set, and if the method is a POST, then it is used to determine the "real" intended HTTP method.
The _method request parameter can also be used to determine the HTTP method, but only if enableHttpMethodParameterOverride() has been called.
The method is always an uppercased string.
string | The request method |
getRealMethod() |
Gets the "real" request method.
string | The request method |
getMethod() |
Gets the mime type associated with the format.
string | $format | The format |
string|null | The associated mime type (null if not found) |
Gets the mime types associated with the format.
string | $format | The format |
array | The associated mime types |
Gets the format associated with the mime type.
string | $mimeType | The associated mime type |
string|null | The format (null if not found) |
Associates a format with mime types.
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) |
Gets the request format.
Here is the process to determine the format:
string|null | $default | The default format |
string | The request format |
Sets the request format.
string | $format | The request format |
Gets the format associated with the request.
string|null | The format (null if no content type is present) |
Sets the default locale.
string | $locale |
Get the default locale.
string |
Sets the locale.
string | $locale |
Get the locale.
string |
Checks if the request method is of specified type.
string | $method | Uppercase request method (GET, POST etc) |
bool |
Checks whether or not the method is safe.
bool |
https://tools.ietf.org/html/rfc7231#section-4.2.1 |
Checks whether or not the method is idempotent.
bool |
Checks whether the method is cacheable or not.
bool |
https://tools.ietf.org/html/rfc7231#section-4.2.3 |
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).
string |
Returns the request body content.
bool | $asResource | If true, a resource will be returned |
string|resource | The request body content or a resource to read the body stream |
LogicException |
Gets the Etags.
array | The entity tags |
bool |
Returns the preferred language.
array | $locales | An array of ordered available locales |
string|null | The preferred locale |
Gets a list of languages acceptable by the client browser.
array | Languages ordered in the user browser preferences |
Gets a list of charsets acceptable by the client browser.
array | List of charsets in preferable order |
Gets a list of encodings acceptable by the client browser.
array | List of encodings in preferable order |
Gets a list of content types acceptable by the client browser.
array | List of content types in preferable order |
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:
bool | true if the request is an XMLHttpRequest, false otherwise |
http://en.wikipedia.org/wiki/List_of_Ajax_frameworks#JavaScript |
Prepares the base URL.
string |
Prepares the base path.
string | base path |
Prepares the path info.
string | path info |
Initializes HTTP request formats.
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.
bool | true if the request came from a trusted proxy, false otherwise |
© 2004–2017 Fabien Potencier
Licensed under the MIT License.
https://api.symfony.com/4.1/Symfony/Component/HttpFoundation/ApacheRequest.html