4 * @see https://github.com/laminas/laminas-diactoros for the canonical source repository
5 * @copyright https://github.com/laminas/laminas-diactoros/blob/master/COPYRIGHT.md
6 * @license https://github.com/laminas/laminas-diactoros/blob/master/LICENSE.md New BSD License
9 declare(strict_types=1);
11 namespace Laminas\Diactoros;
13 use function preg_match;
16 * Return HTTP protocol version (X.Y) as discovered within a `$_SERVER` array.
18 * @throws Exception\UnrecognizedProtocolVersionException if the
19 * $server['SERVER_PROTOCOL'] value is malformed.
21 function marshalProtocolVersionFromSapi(array $server) : string
23 if (! isset($server['SERVER_PROTOCOL'])) {
27 if (! preg_match('#^(HTTP/)?(?P<version>[1-9]\d*(?:\.\d)?)$#', $server['SERVER_PROTOCOL'], $matches)) {
28 throw Exception\UnrecognizedProtocolVersionException::forVersion(
29 (string) $server['SERVER_PROTOCOL']
33 return $matches['version'];