Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Request.php

function Request::overrideGlobals

Overrides the PHP global variables according to this request instance.

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

File

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

Class

Request
Request represents an HTTP request.

Namespace

Symfony\Component\HttpFoundation

Code

public function overrideGlobals() : void {
    $this->server
        ->set('QUERY_STRING', static::normalizeQueryString(http_build_query($this->query
        ->all(), '', '&')));
    $_GET = $this->query
        ->all();
    $_POST = $this->request
        ->all();
    $_SERVER = $this->server
        ->all();
    $_COOKIE = $this->cookies
        ->all();
    foreach ($this->headers
        ->all() as $key => $value) {
        $key = strtoupper(str_replace('-', '_', $key));
        if (\in_array($key, [
            'CONTENT_TYPE',
            'CONTENT_LENGTH',
            'CONTENT_MD5',
        ], true)) {
            $_SERVER[$key] = implode(', ', $value);
        }
        else {
            $_SERVER['HTTP_' . $key] = implode(', ', $value);
        }
    }
    $request = [
        'g' => $_GET,
        'p' => $_POST,
        'c' => $_COOKIE,
    ];
    $requestOrder = \ini_get('request_order') ?: \ini_get('variables_order');
    $requestOrder = preg_replace('#[^cgp]#', '', strtolower($requestOrder)) ?: 'gp';
    $_REQUEST = [
        [],
    ];
    foreach (str_split($requestOrder) as $order) {
        $_REQUEST[] = $request[$order];
    }
    $_REQUEST = array_merge(...$_REQUEST);
}
RSS feed
Powered by Drupal