You are here

public static function Request::create in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/symfony/http-foundation/Request.php \Symfony\Component\HttpFoundation\Request::create()

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:

Return value

Request A Request instance

274 calls to Request::create()
AcceptHeaderMatcherTest::testAcceptFiltering in core/modules/system/tests/modules/accept_header_routing_test/tests/Unit/AcceptHeaderMatcherTest.php
Tests that requests using Accept headers get filtered correctly.
AcceptHeaderMatcherTest::testNoRouteFound in core/modules/system/tests/modules/accept_header_routing_test/tests/Unit/AcceptHeaderMatcherTest.php
Confirms that the AcceptHeaderMatcher throws an exception for no-route.
AccessAwareRouter::match in core/lib/Drupal/Core/Routing/AccessAwareRouter.php
AjaxResponseTest::testPrepareResponseForIeFormRequestsWithFileUpload in core/tests/Drupal/Tests/Core/Ajax/AjaxResponseTest.php
Tests the support for IE specific headers in file uploads.
AllowToolbarPathTest::testAllowToolbarPath in core/modules/toolbar/tests/src/Unit/PageCache/AllowToolbarPathTest.php
Asserts that caching is allowed if the request goes to toolbar subtree.

... See full list

File

vendor/symfony/http-foundation/Request.php, line 308

Class

Request
Request represents an HTTP request.

Namespace

Symfony\Component\HttpFoundation

Code

public static function create($uri, $method = 'GET', $parameters = array(), $cookies = array(), $files = array(), $server = array(), $content = null) {
  $server = array_replace(array(
    'SERVER_NAME' => 'localhost',
    'SERVER_PORT' => 80,
    'HTTP_HOST' => 'localhost',
    'HTTP_USER_AGENT' => 'Symfony/2.X',
    'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
    'HTTP_ACCEPT_LANGUAGE' => 'en-us,en;q=0.5',
    'HTTP_ACCEPT_CHARSET' => 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
    'REMOTE_ADDR' => '127.0.0.1',
    'SCRIPT_NAME' => '',
    'SCRIPT_FILENAME' => '',
    'SERVER_PROTOCOL' => 'HTTP/1.1',
    'REQUEST_TIME' => time(),
  ), $server);
  $server['PATH_INFO'] = '';
  $server['REQUEST_METHOD'] = strtoupper($method);
  $components = parse_url($uri);
  if (isset($components['host'])) {
    $server['SERVER_NAME'] = $components['host'];
    $server['HTTP_HOST'] = $components['host'];
  }
  if (isset($components['scheme'])) {
    if ('https' === $components['scheme']) {
      $server['HTTPS'] = 'on';
      $server['SERVER_PORT'] = 443;
    }
    else {
      unset($server['HTTPS']);
      $server['SERVER_PORT'] = 80;
    }
  }
  if (isset($components['port'])) {
    $server['SERVER_PORT'] = $components['port'];
    $server['HTTP_HOST'] = $server['HTTP_HOST'] . ':' . $components['port'];
  }
  if (isset($components['user'])) {
    $server['PHP_AUTH_USER'] = $components['user'];
  }
  if (isset($components['pass'])) {
    $server['PHP_AUTH_PW'] = $components['pass'];
  }
  if (!isset($components['path'])) {
    $components['path'] = '/';
  }
  switch (strtoupper($method)) {
    case 'POST':
    case 'PUT':
    case 'DELETE':
      if (!isset($server['CONTENT_TYPE'])) {
        $server['CONTENT_TYPE'] = 'application/x-www-form-urlencoded';
      }

    // no break
    case 'PATCH':
      $request = $parameters;
      $query = array();
      break;
    default:
      $request = array();
      $query = $parameters;
      break;
  }
  $queryString = '';
  if (isset($components['query'])) {
    parse_str(html_entity_decode($components['query']), $qs);
    if ($query) {
      $query = array_replace($qs, $query);
      $queryString = http_build_query($query, '', '&');
    }
    else {
      $query = $qs;
      $queryString = $components['query'];
    }
  }
  elseif ($query) {
    $queryString = http_build_query($query, '', '&');
  }
  $server['REQUEST_URI'] = $components['path'] . ('' !== $queryString ? '?' . $queryString : '');
  $server['QUERY_STRING'] = $queryString;
  return self::createRequestFromFactory($query, $request, array(), $cookies, $files, $server, $content);
}