You are here

public function TrustedHostsRequestFactory::createRequest in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Http/TrustedHostsRequestFactory.php \Drupal\Core\Http\TrustedHostsRequestFactory::createRequest()
  2. 10 core/lib/Drupal/Core/Http/TrustedHostsRequestFactory.php \Drupal\Core\Http\TrustedHostsRequestFactory::createRequest()

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

\Symfony\Component\HttpFoundation\Request A new request object.

File

core/lib/Drupal/Core/Http/TrustedHostsRequestFactory.php, line 61

Class

TrustedHostsRequestFactory
Provides a request factory for requests using host verification.

Namespace

Drupal\Core\Http

Code

public function createRequest(array $query = [], array $request = [], array $attributes = [], array $cookies = [], array $files = [], array $server = [], $content = NULL) {
  if (empty($server['HTTP_HOST']) || $server['HTTP_HOST'] === 'localhost' && $this->host !== 'localhost') {
    $server['HTTP_HOST'] = $this->host;
  }
  $request = new Request($query, $request, $attributes, $cookies, $files, $server, $content);

  // Replace ParameterBag with InputBag for compatibility with Symfony 5.
  // @todo Remove this when Symfony 4 is no longer supported.
  foreach ([
    'request',
    'query',
    'cookies',
  ] as $bag) {
    if (!$bag instanceof SymfonyInputBag) {
      $request->{$bag} = new InputBag($request->{$bag}
        ->all());
    }
  }
  return $request;
}