PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / 1.10.20
WCPOS – Point of Sale (POS) plugin for WooCommerce v1.10.20
1.10.20 1.10.19 1.10.18 1.10.17 1.10.16 1.10.15 1.10.13 1.10.14 1.10.12 1.10.11 1.10.10 1.10.9 1.10.8 untagged-3d9b7ccddc54df87c672 1.10.7 1.10.6 1.10.5 1.10.3 1.10.4 1.10.2 1.10.1 1.10.0 1.9.17 1.9.15 1.9.16 All 164 releases
woocommerce-pos / vendor_prefixed / guzzlehttp / psr7 / src / Header.php

Header.php in WCPOS – Point of Sale (POS) plugin for WooCommerce 1.10.20, at vendor_prefixed/guzzlehttp/psr7/src/Header.php

140 lines 4.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare (strict_types=1);
4 namespace WCPOS\Vendor\GuzzleHttp\Psr7;
5
6 final class Header
7 {
8 private function __construct()
9 {
10 }
11 /**
12 * Parses semicolon-separated header parameters into associative arrays, one
13 * per comma-separated header value. Parameters without a value are appended
14 * as values under integer keys.
15 *
16 * @param string|array $header Header to parse into components.
17 */
18 public static function parse($header) : array
19 {
20 static $trimmed = "\"' \n\t\r";
21 $params = $matches = [];
22 foreach ((array) $header as $value) {
23 foreach (self::splitList($value) as $val) {
24 $part = [];
25 foreach (self::splitParameters($val) as $kvp) {
26 $count = \preg_match_all('/<[^>]+>|[^=]+/', $kvp, $matches);
27 if ($count === \false) {
28 throw new \RuntimeException('Unable to parse header parameters: ' . \preg_last_error_msg());
29 }
30 if ($count !== 0) {
31 $m = $matches[0];
32 if (isset($m[1])) {
33 $part[\trim($m[0], $trimmed)] = \trim($m[1], $trimmed);
34 } else {
35 $part[] = \trim($m[0], $trimmed);
36 }
37 }
38 }
39 if ($part) {
40 $params[] = $part;
41 }
42 }
43 }
44 return $params;
45 }
46 /**
47 * Split a header value into semicolon-separated parameters.
48 *
49 * @return string[]
50 */
51 private static function splitParameters(string $value) : array
52 {
53 $values = [];
54 $start = 0;
55 $isQuoted = \false;
56 $isEscaped = \false;
57 for ($i = 0, $max = \strlen($value); $i < $max; ++$i) {
58 $char = $value[$i];
59 if ($isEscaped) {
60 $isEscaped = \false;
61 continue;
62 }
63 if ($isQuoted && $char === '\\') {
64 $isEscaped = \true;
65 continue;
66 }
67 if ($char === '"') {
68 $isQuoted = !$isQuoted;
69 continue;
70 }
71 if (!$isQuoted && $char === ';') {
72 $values[] = \substr($value, $start, $i - $start);
73 $start = $i + 1;
74 }
75 }
76 $values[] = \substr($value, $start);
77 return $values;
78 }
79 /**
80 * Splits an HTTP header defined to contain a comma-separated list into each
81 * individual value. Empty values are removed.
82 *
83 * Example headers include `accept`, `cache-control`, and `if-none-match`.
84 *
85 * This method must not be used to parse headers that are not defined as a
86 * list, such as `user-agent` or `set-cookie`.
87 *
88 * @param string|string[] $values Header value as returned by
89 * MessageInterface::getHeader()
90 *
91 * @return string[]
92 */
93 public static function splitList($values) : array
94 {
95 if (!\is_array($values)) {
96 $values = [$values];
97 }
98 $result = [];
99 foreach ($values as $value) {
100 if (!\is_string($value)) {
101 throw new \TypeError('$header must either be a string or an array containing strings.');
102 }
103 $v = '';
104 $isQuoted = \false;
105 $isEscaped = \false;
106 for ($i = 0, $max = \strlen($value); $i < $max; ++$i) {
107 if ($isEscaped) {
108 $v .= $value[$i];
109 $isEscaped = \false;
110 continue;
111 }
112 if (!$isQuoted && $value[$i] === ',') {
113 $v = \trim($v, " \t\n\r");
114 if ($v !== '') {
115 $result[] = $v;
116 }
117 $v = '';
118 continue;
119 }
120 if ($isQuoted && $value[$i] === '\\') {
121 $isEscaped = \true;
122 $v .= $value[$i];
123 continue;
124 }
125 if ($value[$i] === '"') {
126 $isQuoted = !$isQuoted;
127 $v .= $value[$i];
128 continue;
129 }
130 $v .= $value[$i];
131 }
132 $v = \trim($v, " \t\n\r");
133 if ($v !== '') {
134 $result[] = $v;
135 }
136 }
137 return $result;
138 }
139 }
140