25ed91cb772bd45bdba6e866c8b5dc606e4bc4cf
[GitHub/WoltLab/WCF.git] /
1 <?php
2
3 /**
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
7 */
8
9 declare(strict_types=1);
10
11 namespace Laminas\Diactoros;
12
13 use function preg_match;
14
15 /**
16 * Return HTTP protocol version (X.Y) as discovered within a `$_SERVER` array.
17 *
18 * @throws Exception\UnrecognizedProtocolVersionException if the
19 * $server['SERVER_PROTOCOL'] value is malformed.
20 */
21 function marshalProtocolVersionFromSapi(array $server) : string
22 {
23 if (! isset($server['SERVER_PROTOCOL'])) {
24 return '1.1';
25 }
26
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']
30 );
31 }
32
33 return $matches['version'];
34 }