PluginProbe
Media Cloud Sync / 1.2.5
Media Cloud Sync v1.2.5
1.4.2 1.4.1 1.4.0 1.3.12 1.3.11 1.3.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.2.0 1.2.10 1.2.11 1.2.12 1.2.13 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 All 36 releases
media-cloud-sync / includes / sdk / s3 / GuzzleHttp / Psr7 / Header.php

Header.php in Media Cloud Sync 1.2.5, at includes/sdk/s3/GuzzleHttp/Psr7/Header.php

67 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Dudlewebs\WPMCS\s3\GuzzleHttp\Psr7;
4
5 final class Header
6 {
7 /**
8 * Parse an array of header values containing ";" separated data into an
9 * array of associative arrays representing the header key value pair data
10 * of the header. When a parameter does not contain a value, but just
11 * contains a key, this function will inject a key with a '' string value.
12 *
13 * @param string|array $header Header to parse into components.
14 *
15 * @return array Returns the parsed header values.
16 */
17 public static function parse($header)
18 {
19 static $trimmed = "\"' \n\t\r";
20 $params = $matches = [];
21 foreach (self::normalize($header) as $val) {
22 $part = [];
23 foreach (\preg_split('/;(?=([^"]*"[^"]*")*[^"]*$)/', $val) as $kvp) {
24 if (\preg_match_all('/<[^>]+>|[^=]+/', $kvp, $matches)) {
25 $m = $matches[0];
26 if (isset($m[1])) {
27 $part[\trim($m[0], $trimmed)] = \trim($m[1], $trimmed);
28 } else {
29 $part[] = \trim($m[0], $trimmed);
30 }
31 }
32 }
33 if ($part) {
34 $params[] = $part;
35 }
36 }
37 return $params;
38 }
39 /**
40 * Converts an array of header values that may contain comma separated
41 * headers into an array of headers with no comma separated values.
42 *
43 * @param string|array $header Header to normalize.
44 *
45 * @return array Returns the normalized header field values.
46 */
47 public static function normalize($header)
48 {
49 if (!\is_array($header)) {
50 return \array_map('trim', \explode(',', $header));
51 }
52 $result = [];
53 foreach ($header as $value) {
54 foreach ((array) $value as $v) {
55 if (\strpos($v, ',') === \false) {
56 $result[] = $v;
57 continue;
58 }
59 foreach (\preg_split('/,(?=([^"]*"[^"]*")*[^"]*$)/', $v) as $vv) {
60 $result[] = \trim($vv);
61 }
62 }
63 }
64 return $result;
65 }
66 }
67