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.2.3 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.7.0 3.7.1 3.7.2 3.7.3 3.7.4 3.8.0 3.8.1 3.8.2 3.8.3 3.9.0 3.9.1 3.9.10 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9
tutor / ecommerce / PaymentGateways / Paypal / vendor / guzzlehttp / psr7 / src / Header.php
tutor / ecommerce / PaymentGateways / Paypal / vendor / guzzlehttp / psr7 / src Last commit date
Exception 1 year ago AppendStream.php 2 months ago BufferStream.php 2 months ago CachingStream.php 2 months ago DroppingStream.php 2 months ago FnStream.php 2 months ago Header.php 2 months ago HttpFactory.php 1 year ago InflateStream.php 1 year ago LazyOpenStream.php 1 year ago LimitStream.php 2 months ago Message.php 2 months ago MessageTrait.php 2 months ago MimeType.php 2 months ago MultipartStream.php 2 months ago NoSeekStream.php 2 months ago PumpStream.php 2 months ago Query.php 1 year ago Request.php 2 months ago Response.php 2 months ago Rfc3986.php 2 months ago Rfc7230.php 2 months ago ServerRequest.php 2 months ago Stream.php 2 months ago StreamDecoratorTrait.php 2 months ago StreamWrapper.php 2 months ago UploadedFile.php 2 months ago Uri.php 2 months ago UriComparator.php 2 months ago UriNormalizer.php 2 months ago UriResolver.php 2 months ago Utils.php 2 months ago
Header.php
179 lines
1 <?php
2
3 declare(strict_types=1);
4
5 namespace GuzzleHttp\Psr7;
6
7 final class Header
8 {
9 /**
10 * Parse an array of header values containing ";" separated data into an
11 * array of associative arrays representing the header key value pair data
12 * of the header. When a parameter does not contain a value, but just
13 * contains a key, this function will inject a key with a '' string value.
14 *
15 * @param string|array $header Header to parse into components.
16 */
17 public static function parse($header): array
18 {
19 static $trimmed = "\"' \n\t\r";
20 $params = $matches = [];
21
22 foreach ((array) $header as $value) {
23 foreach (self::splitList($value) as $val) {
24 $part = [];
25 foreach (self::splitParameters($val) as $kvp) {
26 if (preg_match_all('/<[^>]+>|[^=]+/', $kvp, $matches)) {
27 $m = $matches[0];
28 if (isset($m[1])) {
29 $part[trim($m[0], $trimmed)] = trim($m[1], $trimmed);
30 } else {
31 $part[] = trim($m[0], $trimmed);
32 }
33 }
34 }
35 if ($part) {
36 $params[] = $part;
37 }
38 }
39 }
40
41 return $params;
42 }
43
44 /**
45 * Split a header value into semicolon-separated parameters.
46 *
47 * @return string[]
48 */
49 private static function splitParameters(string $value): array
50 {
51 $values = [];
52 $start = 0;
53 $isQuoted = false;
54 $isEscaped = false;
55
56 for ($i = 0, $max = \strlen($value); $i < $max; ++$i) {
57 $char = $value[$i];
58
59 if ($isEscaped) {
60 $isEscaped = false;
61
62 continue;
63 }
64
65 if ($isQuoted && $char === '\\') {
66 $isEscaped = true;
67
68 continue;
69 }
70
71 if ($char === '"') {
72 $isQuoted = !$isQuoted;
73
74 continue;
75 }
76
77 if (!$isQuoted && $char === ';') {
78 $values[] = \substr($value, $start, $i - $start);
79 $start = $i + 1;
80 }
81 }
82
83 $values[] = \substr($value, $start);
84
85 return $values;
86 }
87
88 /**
89 * Converts an array of header values that may contain comma separated
90 * headers into an array of headers with no comma separated values.
91 *
92 * @param string|array $header Header to normalize.
93 *
94 * @deprecated Use self::splitList() instead.
95 */
96 public static function normalize($header): array
97 {
98 $result = [];
99 foreach ((array) $header as $value) {
100 foreach (self::splitList($value) as $parsed) {
101 $result[] = $parsed;
102 }
103 }
104
105 return $result;
106 }
107
108 /**
109 * Splits a HTTP header defined to contain a comma-separated list into
110 * each individual value. Empty values will be removed.
111 *
112 * Example headers include 'accept', 'cache-control' and 'if-none-match'.
113 *
114 * This method must not be used to parse headers that are not defined as
115 * a list, such as 'user-agent' or 'set-cookie'.
116 *
117 * @param string|string[] $values Header value as returned by MessageInterface::getHeader()
118 *
119 * @return string[]
120 */
121 public static function splitList($values): array
122 {
123 if (!\is_array($values)) {
124 $values = [$values];
125 }
126
127 $result = [];
128 foreach ($values as $value) {
129 if (!\is_string($value)) {
130 throw new \TypeError('$header must either be a string or an array containing strings.');
131 }
132
133 $v = '';
134 $isQuoted = false;
135 $isEscaped = false;
136 for ($i = 0, $max = \strlen($value); $i < $max; ++$i) {
137 if ($isEscaped) {
138 $v .= $value[$i];
139 $isEscaped = false;
140
141 continue;
142 }
143
144 if (!$isQuoted && $value[$i] === ',') {
145 $v = \trim($v);
146 if ($v !== '') {
147 $result[] = $v;
148 }
149
150 $v = '';
151 continue;
152 }
153
154 if ($isQuoted && $value[$i] === '\\') {
155 $isEscaped = true;
156 $v .= $value[$i];
157
158 continue;
159 }
160 if ($value[$i] === '"') {
161 $isQuoted = !$isQuoted;
162 $v .= $value[$i];
163
164 continue;
165 }
166
167 $v .= $value[$i];
168 }
169
170 $v = \trim($v);
171 if ($v !== '') {
172 $result[] = $v;
173 }
174 }
175
176 return $result;
177 }
178 }
179