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

Breadcrumb

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

function ServerRequestCreator::fromGlobals

Overrides ServerRequestCreatorInterface::fromGlobals

File

vendor/nyholm/psr7-server/src/ServerRequestCreator.php, line 45

Class

ServerRequestCreator
@author Tobias Nyholm <tobias.nyholm@gmail.com> @author Martijn van der Ven <martijn@vanderven.se>

Namespace

Nyholm\Psr7Server

Code

public function fromGlobals() : ServerRequestInterface {
    $server = $_SERVER;
    if (false === isset($server['REQUEST_METHOD'])) {
        $server['REQUEST_METHOD'] = 'GET';
    }
    $headers = \function_exists('getallheaders') ? getallheaders() : static::getHeadersFromServer($_SERVER);
    $post = null;
    if ('POST' === $this->getMethodFromEnv($server)) {
        foreach ($headers as $headerName => $headerValue) {
            if (true === \is_int($headerName) || 'content-type' !== \strtolower($headerName)) {
                continue;
            }
            if (\in_array(\strtolower(\trim(\explode(';', $headerValue, 2)[0])), [
                'application/x-www-form-urlencoded',
                'multipart/form-data',
            ])) {
                $post = $_POST;
                break;
            }
        }
    }
    return $this->fromArrays($server, $headers, $_COOKIE, $_GET, $post, $_FILES, \fopen('php://input', 'r') ?: null);
}

API Navigation

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