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

Breadcrumb

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

function ServerRequest::fromGlobals

Return a ServerRequest populated with superglobals: $_GET $_POST $_COOKIE $_FILES $_SERVER

File

vendor/guzzlehttp/psr7/src/ServerRequest.php, line 166

Class

ServerRequest
Server-side HTTP request

Namespace

GuzzleHttp\Psr7

Code

public static function fromGlobals() : ServerRequestInterface {
    $method = $_SERVER['REQUEST_METHOD'] ?? 'GET';
    $headers = getallheaders();
    $uri = self::getUriFromGlobals();
    $body = new CachingStream(new LazyOpenStream('php://input', 'r+'));
    $protocol = isset($_SERVER['SERVER_PROTOCOL']) ? str_replace('HTTP/', '', $_SERVER['SERVER_PROTOCOL']) : '1.1';
    $serverRequest = new ServerRequest($method, $uri, $headers, $body, $protocol, $_SERVER);
    return $serverRequest->withCookieParams($_COOKIE)
        ->withQueryParams($_GET)
        ->withParsedBody($_POST)
        ->withUploadedFiles(self::normalizeFiles($_FILES));
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal