You are here

public static function ServerRequestFactory::marshalHeaders in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/zendframework/zend-diactoros/src/ServerRequestFactory.php \Zend\Diactoros\ServerRequestFactory::marshalHeaders()

Marshal headers from $_SERVER

Parameters

array $server:

Return value

array

1 call to ServerRequestFactory::marshalHeaders()
ServerRequestFactory::fromGlobals in vendor/zendframework/zend-diactoros/src/ServerRequestFactory.php
Create a request from the supplied superglobal values.

File

vendor/zendframework/zend-diactoros/src/ServerRequestFactory.php, line 195

Class

ServerRequestFactory
Class for marshaling a request object from the current PHP environment.

Namespace

Zend\Diactoros

Code

public static function marshalHeaders(array $server) {
  $headers = [];
  foreach ($server as $key => $value) {
    if (strpos($key, 'HTTP_COOKIE') === 0) {

      // Cookies are handled using the $_COOKIE superglobal
      continue;
    }
    if ($value && strpos($key, 'HTTP_') === 0) {
      $name = strtr(substr($key, 5), '_', ' ');
      $name = strtr(ucwords(strtolower($name)), ' ', '-');
      $name = strtolower($name);
      $headers[$name] = $value;
      continue;
    }
    if ($value && strpos($key, 'CONTENT_') === 0) {
      $name = substr($key, 8);

      // Content-
      $name = 'Content-' . ($name == 'MD5' ? $name : ucfirst(strtolower($name)));
      $name = strtolower($name);
      $headers[$name] = $value;
      continue;
    }
  }
  return $headers;
}