class TrustedHostsRequestFactory (View source)

Provides a request factory for requests using host verification.

Because the trusted host patterns for requests are stored statically, they are consulted even for fake request created with Request::create(), whose host is 'localhost' by default. Such requests would fail host verification unless 'localhost' matches one of the trusted host patterns. To circumvent this problem, this factory injects the server variables from the main request into each newly created request, so that the host is correctly set even for fake requests and they properly pass host verification.

Properties

protected string $host

The host of the main request.

Methods

__construct(string $host)

Creates a new TrustedHostsRequestFactory.

Request
createRequest(array $query = [], array $request = [], array $attributes = [], array $cookies = [], array $files = [], array $server = [], string $content = NULL)

Creates a new request object.

Details

__construct(string $host)

Creates a new TrustedHostsRequestFactory.

Parameters

string $host

The host of the main request.

Request createRequest(array $query = [], array $request = [], array $attributes = [], array $cookies = [], array $files = [], array $server = [], string $content = NULL)

Creates a new request object.

Parameters

array $query

(optional) The query (GET) or request (POST) parameters.

array $request

(optional) An array of request variables.

array $attributes

(optional) An array of attributes.

array $cookies

(optional) The request cookies ($_COOKIE).

array $files

(optional) The request files ($_FILES).

array $server

(optional) The server parameters ($_SERVER).

string $content

(optional) The raw body data.

Return Value

Request

A new request object.