# Class HttpSoft\ServerRequest\SapiNormalizer

Normalizes the necessary data for creating a HttpSoft\Message\ServerRequest from server parameters, implements HttpSoft\ServerRequest\ServerNormalizerInterface.

Source code on GitHub.

use HttpSoft\ServerRequest\SapiNormalizer;

$normalizer = new SapiNormalizer();
$server = [
    'HTTPS' => 'on',
    'SERVER_PORT' => '443',
    'REQUEST_METHOD' => 'DELETE',
    'SERVER_PROTOCOL' => 'HTTP/2',
    'HTTP_HOST' => 'example.com',
    'HTTP_CACHE_CONTROL' => 'max-age=0',
    'HTTP_X_FORWARDED_PROTO' => 'https',
    'CONTENT_TYPE' => 'text/html; charset=UTF-8',
    'REQUEST_URI' => '/path?id=2',
    'QUERY_STRING' => 'id=2',
];

$normalizer->normalizeMethod($server); // 'DELETE'
$normalizer->normalizeProtocolVersion($server); // '2'
$normalizer->normalizeUri($server)->__toString(); // 'https://example.com/path?id=2'
$normalizer->normalizeHeaders($server);
// Notice: only the `CONTENT_*` and `HTTP_* ' headers will be normalized.
/*
[
    'Host' => 'example.com',
    'Cache-Control' => 'max-age=0',
    'X-Forwarded-Proto' => 'https',
    'Content-Type' => 'text/html; charset=UTF-8',
];
*/

# Public methods

The methods that are defined in the HttpSoft\ServerRequest\ServerNormalizerInterface interface, are shown below.

# normalizeMethod

Returns a normalized HTTP request method from server parameters (by default: 'GET').

public function normalizeMethod(array $server): string;

# normalizeProtocolVersion

Returns a normalized HTTP protocol version from server parameters (by default: '1.1').

public function normalizeProtocolVersion(array $server): string;

# normalizeUri

Returns a normalized request URI (Psr\Http\Message\UriInterface instance) from server parameters.

public function normalizeUri(array $server): UriInterface;

# normalizeHeaders

Returns HTTP headers with normalized names from server parameters.

public function normalizeHeaders(array $server): array;