PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 18.4
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v18.4
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / vendor_prefixed / guzzlehttp / psr7 / src / Header.php

Header.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 18.4, at vendor_prefixed/guzzlehttp/psr7/src/Header.php

67 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace YoastSEO_Vendor\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