Verzeichnisstruktur phpBB-3.3.15


Veröffentlicht
28.08.2024

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

Query.php

Zuletzt modifiziert: 02.04.2025, 15:03 - Dateigröße: 3.41 KiB


001  <?php
002   
003  namespace GuzzleHttp\Psr7;
004   
005  final class Query
006  {
007      /**
008       * Parse a query string into an associative array.
009       *
010       * If multiple values are found for the same key, the value of that key
011       * value pair will become an array. This function does not parse nested
012       * PHP style arrays into an associative array (e.g., `foo[a]=1&foo[b]=2`
013       * will be parsed into `['foo[a]' => '1', 'foo[b]' => '2'])`.
014       *
015       * @param string   $str         Query string to parse
016       * @param int|bool $urlEncoding How the query string is encoded
017       *
018       * @return array
019       */
020      public static function parse($str, $urlEncoding = true)
021      {
022          $result = [];
023   
024          if ($str === '') {
025              return $result;
026          }
027   
028          if ($urlEncoding === true) {
029              $decoder = function ($value) {
030                  return rawurldecode(str_replace('+', ' ', $value));
031              };
032          } elseif ($urlEncoding === PHP_QUERY_RFC3986) {
033              $decoder = 'rawurldecode';
034          } elseif ($urlEncoding === PHP_QUERY_RFC1738) {
035              $decoder = 'urldecode';
036          } else {
037              $decoder = function ($str) {
038                  return $str;
039              };
040          }
041   
042          foreach (explode('&', $str) as $kvp) {
043              $parts = explode('=', $kvp, 2);
044              $key = $decoder($parts[0]);
045              $value = isset($parts[1]) ? $decoder($parts[1]) : null;
046              if (!isset($result[$key])) {
047                  $result[$key] = $value;
048              } else {
049                  if (!is_array($result[$key])) {
050                      $result[$key] = [$result[$key]];
051                  }
052                  $result[$key][] = $value;
053              }
054          }
055   
056          return $result;
057      }
058   
059      /**
060       * Build a query string from an array of key value pairs.
061       *
062       * This function can use the return value of `parse()` to build a query
063       * string. This function does not modify the provided keys when an array is
064       * encountered (like `http_build_query()` would).
065       *
066       * @param array     $params   Query string parameters.
067       * @param int|false $encoding Set to false to not encode, PHP_QUERY_RFC3986
068       *                            to encode using RFC3986, or PHP_QUERY_RFC1738
069       *                            to encode using RFC1738.
070       *
071       * @return string
072       */
073      public static function build(array $params, $encoding = PHP_QUERY_RFC3986)
074      {
075          if (!$params) {
076              return '';
077          }
078   
079          if ($encoding === false) {
080              $encoder = function ($str) {
081                  return $str;
082              };
083          } elseif ($encoding === PHP_QUERY_RFC3986) {
084              $encoder = 'rawurlencode';
085          } elseif ($encoding === PHP_QUERY_RFC1738) {
086              $encoder = 'urlencode';
087          } else {
088              throw new \InvalidArgumentException('Invalid type');
089          }
090   
091          $qs = '';
092          foreach ($params as $k => $v) {
093              $k = $encoder($k);
094              if (!is_array($v)) {
095                  $qs .= $k;
096                  if ($v !== null) {
097                      $qs .= '=' . $encoder($v);
098                  }
099                  $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