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

Breadcrumb

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

function ServerRequestCreator::getHeadersFromServer

Implementation from Laminas\Diactoros\marshalHeadersFromSapi().

Overrides ServerRequestCreatorInterface::getHeadersFromServer

1 call to ServerRequestCreator::getHeadersFromServer()
ServerRequestCreator::fromGlobals in vendor/nyholm/psr7-server/src/ServerRequestCreator.php
Create a new server request from the current environment variables. Defaults to a GET request to minimise the risk of an \InvalidArgumentException. Includes the current request headers as supplied by the server through `getallheaders()`. If…

File

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

Class

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

Namespace

Nyholm\Psr7Server

Code

public static function getHeadersFromServer(array $server) : array {
    $headers = [];
    foreach ($server as $key => $value) {
        // Apache prefixes environment variables with REDIRECT_
        // if they are added by rewrite rules
        if (0 === \strpos($key, 'REDIRECT_')) {
            $key = \substr($key, 9);
            // We will not overwrite existing variables with the
            // prefixed versions, though
            if (\array_key_exists($key, $server)) {
                continue;
            }
        }
        if ($value && 0 === \strpos($key, 'HTTP_')) {
            $name = \strtr(\strtolower(\substr($key, 5)), '_', '-');
            $headers[$name] = $value;
            continue;
        }
        if ($value && 0 === \strpos($key, 'CONTENT_')) {
            $name = 'content-' . \strtolower(\substr($key, 8));
            $headers[$name] = $value;
            continue;
        }
    }
    return $headers;
}

API Navigation

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