PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 1.2.20
Booking for Appointments and Events Calendar – Amelia v1.2.20
2.4.4 2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / vendor / guzzlehttp / psr7 / src / Query.php
ameliabooking / vendor / guzzlehttp / psr7 / src Last commit date
AppendStream.php 3 years ago BufferStream.php 3 years ago CachingStream.php 3 years ago DroppingStream.php 3 years ago FnStream.php 3 years ago Header.php 5 years ago InflateStream.php 3 years ago LazyOpenStream.php 3 years ago LimitStream.php 3 years ago Message.php 3 years ago MessageTrait.php 2 years ago MimeType.php 5 years ago MultipartStream.php 3 years ago NoSeekStream.php 3 years ago PumpStream.php 3 years ago Query.php 4 years ago Request.php 3 years ago Response.php 3 years ago Rfc7230.php 4 years ago ServerRequest.php 3 years ago Stream.php 3 years ago StreamDecoratorTrait.php 3 years ago StreamWrapper.php 3 years ago UploadedFile.php 3 years ago Uri.php 3 years ago UriComparator.php 2 years ago UriNormalizer.php 3 years ago UriResolver.php 3 years ago Utils.php 3 years ago functions.php 3 years ago functions_include.php 5 years ago
Query.php
114 lines
1 <?php
2
3 namespace AmeliaGuzzleHttp\Psr7;
4
5 final class Query
6 {
7 /**
8 * Parse a query string into an associative array.
9 *
10 * If multiple values are found for the same key, the value of that key
11 * value pair will become an array. This function does not parse nested
12 * PHP style arrays into an associative array (e.g., `foo[a]=1&foo[b]=2`
13 * will be parsed into `['foo[a]' => '1', 'foo[b]' => '2'])`.
14 *
15 * @param string $str Query string to parse
16 * @param int|bool $urlEncoding How the query string is encoded
17 *
18 * @return array
19 */
20 public static function parse($str, $urlEncoding = true)
21 {
22 $result = [];
23
24 if ($str === '') {
25 return $result;
26 }
27
28 if ($urlEncoding === true) {
29 $decoder = function ($value) {
30 return rawurldecode(str_replace('+', ' ', $value));
31 };
32 } elseif ($urlEncoding === PHP_QUERY_RFC3986) {
33 $decoder = 'rawurldecode';
34 } elseif ($urlEncoding === PHP_QUERY_RFC1738) {
35 $decoder = 'urldecode';
36 } else {
37 $decoder = function ($str) {
38 return $str;
39 };
40 }
41
42 foreach (explode('&', $str) as $kvp) {
43 $parts = explode('=', $kvp, 2);
44 $key = $decoder($parts[0]);
45 $value = isset($parts[1]) ? $decoder($parts[1]) : null;
46 if (!isset($result[$key])) {
47 $result[$key] = $value;
48 } else {
49 if (!is_array($result[$key])) {
50 $result[$key] = [$result[$key]];
51 }
52 $result[$key][] = $value;
53 }
54 }
55
56 return $result;
57 }
58
59 /**
60 * Build a query string from an array of key value pairs.
61 *
62 * This function can use the return value of `parse()` to build a query
63 * string. This function does not modify the provided keys when an array is
64 * encountered (like `http_build_query()` would).
65 *
66 * @param array $params Query string parameters.
67 * @param int|false $encoding Set to false to not encode, PHP_QUERY_RFC3986
68 * to encode using RFC3986, or PHP_QUERY_RFC1738
69 * to encode using RFC1738.
70 *
71 * @return string
72 */
73 public static function build(array $params, $encoding = PHP_QUERY_RFC3986)
74 {
75 if (!$params) {
76 return '';
77 }
78
79 if ($encoding === false) {
80 $encoder = function ($str) {
81 return $str;
82 };
83 } elseif ($encoding === PHP_QUERY_RFC3986) {
84 $encoder = 'rawurlencode';
85 } elseif ($encoding === PHP_QUERY_RFC1738) {
86 $encoder = 'urlencode';
87 } else {
88 throw new \InvalidArgumentException('Invalid type');
89 }
90
91 $qs = '';
92 foreach ($params as $k => $v) {
93 $k = $encoder($k);
94 if (!is_array($v)) {
95 $qs .= $k;
96 if ($v !== null) {
97 $qs .= '=' . $encoder($v);
98 }
99 $qs .= '&';
100 } else {
101 foreach ($v as $vv) {
102 $qs .= $k;
103 if ($vv !== null) {
104 $qs .= '=' . $encoder($vv);
105 }
106 $qs .= '&';
107 }
108 }
109 }
110
111 return $qs ? (string) substr($qs, 0, -1) : '';
112 }
113 }
114