Zend\Diactoros\ServerRequestFactory::marshalHeaders PHP Method

marshalHeaders() public static method

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

Usage Example

Example #1
0
 public static function fromGlobals(array $server = null, array $query = null, array $body = null, array $cookies = null, array $files = null)
 {
     $server = parent::normalizeServer($server);
     $files = parent::normalizeFiles($files);
     $headers = parent::marshalHeaders($server);
     return new ServerRequest($server, $files, parent::marshalUriFromServer($server, $headers), parent::get('REQUEST_METHOD', $server, 'GET'), 'php://input', $headers, $cookies, $query, $body, self::marshalProtocolVersion($server));
 }
All Usage Examples Of Zend\Diactoros\ServerRequestFactory::marshalHeaders