composer package updates
[openemr.git] / vendor / zendframework / zend-diactoros / src / functions / marshal_protocol_version_from_sapi.php
blob915b6da2873bb8e57c4f0f0928dd11b3026d65fe
1 <?php
2 /**
3 * @see https://github.com/zendframework/zend-diactoros for the canonical source repository
4 * @copyright Copyright (c) 2018 Zend Technologies USA Inc. (https://www.zend.com)
5 * @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
6 */
8 namespace Zend\Diactoros;
10 use UnexpectedValueException;
12 use function preg_match;
14 /**
15 * Return HTTP protocol version (X.Y) as discovered within a `$_SERVER` array.
17 * @param array $server
18 * @return string
19 * @throws UnexpectedValueException if the $server['SERVER_PROTOCOL'] value is
20 * malformed.
22 function marshalProtocolVersionFromSapi(array $server)
24 if (! isset($server['SERVER_PROTOCOL'])) {
25 return '1.1';
28 if (! preg_match('#^(HTTP/)?(?P<version>[1-9]\d*(?:\.\d)?)$#', $server['SERVER_PROTOCOL'], $matches)) {
29 throw new UnexpectedValueException(sprintf(
30 'Unrecognized protocol version (%s)',
31 $server['SERVER_PROTOCOL']
32 ));
35 return $matches['version'];