Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

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

Utils.php

Zuletzt modifiziert: 09.10.2024, 12:56 - Dateigröße: 6.96 KiB


 001  <?php
 002  namespace GuzzleHttp;
 003   
 004  use GuzzleHttp\Ring\Client\CurlHandler;
 005  use GuzzleHttp\Ring\Client\CurlMultiHandler;
 006  use GuzzleHttp\Ring\Client\StreamHandler;
 007  use GuzzleHttp\Ring\Client\Middleware;
 008   
 009  /**
 010   * Utility methods used throughout Guzzle.
 011   */
 012  final class Utils
 013  {
 014      /**
 015       * Gets a value from an array using a path syntax to retrieve nested data.
 016       *
 017       * This method does not allow for keys that contain "/". You must traverse
 018       * the array manually or using something more advanced like JMESPath to
 019       * work with keys that contain "/".
 020       *
 021       *     // Get the bar key of a set of nested arrays.
 022       *     // This is equivalent to $collection['foo']['baz']['bar'] but won't
 023       *     // throw warnings for missing keys.
 024       *     GuzzleHttp\get_path($data, 'foo/baz/bar');
 025       *
 026       * @param array  $data Data to retrieve values from
 027       * @param string $path Path to traverse and retrieve a value from
 028       *
 029       * @return mixed|null
 030       */
 031      public static function getPath($data, $path)
 032      {
 033          $path = explode('/', $path);
 034   
 035          while (null !== ($part = array_shift($path))) {
 036              if (!is_array($data) || !isset($data[$part])) {
 037                  return null;
 038              }
 039              $data = $data[$part];
 040          }
 041   
 042          return $data;
 043      }
 044   
 045      /**
 046       * Set a value in a nested array key. Keys will be created as needed to set
 047       * the value.
 048       *
 049       * This function does not support keys that contain "/" or "[]" characters
 050       * because these are special tokens used when traversing the data structure.
 051       * A value may be prepended to an existing array by using "[]" as the final
 052       * key of a path.
 053       *
 054       *     GuzzleHttp\get_path($data, 'foo/baz'); // null
 055       *     GuzzleHttp\set_path($data, 'foo/baz/[]', 'a');
 056       *     GuzzleHttp\set_path($data, 'foo/baz/[]', 'b');
 057       *     GuzzleHttp\get_path($data, 'foo/baz');
 058       *     // Returns ['a', 'b']
 059       *
 060       * @param array  $data  Data to modify by reference
 061       * @param string $path  Path to set
 062       * @param mixed  $value Value to set at the key
 063       *
 064       * @throws \RuntimeException when trying to setPath using a nested path
 065       *     that travels through a scalar value.
 066       */
 067      public static function setPath(&$data, $path, $value)
 068      {
 069          $queue = explode('/', $path);
 070          // Optimization for simple sets.
 071          if (count($queue) === 1) {
 072              $data[$path] = $value;
 073              return;
 074          }
 075   
 076          $current =& $data;
 077          while (null !== ($key = array_shift($queue))) {
 078              if (!is_array($current)) {
 079                  throw new \RuntimeException("Trying to setPath {$path}, but "
 080                      . "{$key} is set and is not an array");
 081              } elseif (!$queue) {
 082                  if ($key == '[]') {
 083                      $current[] = $value;
 084                  } else {
 085                      $current[$key] = $value;
 086                  }
 087              } elseif (isset($current[$key])) {
 088                  $current =& $current[$key];
 089              } else {
 090                  $current[$key] = [];
 091                  $current =& $current[$key];
 092              }
 093          }
 094      }
 095   
 096      /**
 097       * Expands a URI template
 098       *
 099       * @param string $template  URI template
 100       * @param array  $variables Template variables
 101       *
 102       * @return string
 103       */
 104      public static function uriTemplate($template, array $variables)
 105      {
 106          if (function_exists('\\uri_template')) {
 107              return \uri_template($template, $variables);
 108          }
 109   
 110          static $uriTemplate;
 111          if (!$uriTemplate) {
 112              $uriTemplate = new UriTemplate();
 113          }
 114   
 115          return $uriTemplate->expand($template, $variables);
 116      }
 117   
 118      /**
 119       * Wrapper for JSON decode that implements error detection with helpful
 120       * error messages.
 121       *
 122       * @param string $json    JSON data to parse
 123       * @param bool $assoc     When true, returned objects will be converted
 124       *                        into associative arrays.
 125       * @param int    $depth   User specified recursion depth.
 126       * @param int    $options Bitmask of JSON decode options.
 127       *
 128       * @return mixed
 129       * @throws \InvalidArgumentException if the JSON cannot be parsed.
 130       * @link http://www.php.net/manual/en/function.json-decode.php
 131       */
 132      public static function jsonDecode($json, $assoc = false, $depth = 512, $options = 0)
 133      {
 134          static $jsonErrors = [
 135              JSON_ERROR_DEPTH => 'JSON_ERROR_DEPTH - Maximum stack depth exceeded',
 136              JSON_ERROR_STATE_MISMATCH => 'JSON_ERROR_STATE_MISMATCH - Underflow or the modes mismatch',
 137              JSON_ERROR_CTRL_CHAR => 'JSON_ERROR_CTRL_CHAR - Unexpected control character found',
 138              JSON_ERROR_SYNTAX => 'JSON_ERROR_SYNTAX - Syntax error, malformed JSON',
 139              JSON_ERROR_UTF8 => 'JSON_ERROR_UTF8 - Malformed UTF-8 characters, possibly incorrectly encoded'
 140          ];
 141   
 142          $data = \json_decode($json, $assoc, $depth, $options);
 143   
 144          if (JSON_ERROR_NONE !== json_last_error()) {
 145              $last = json_last_error();
 146              throw new \InvalidArgumentException(
 147                  'Unable to parse JSON data: '
 148                  . (isset($jsonErrors[$last])
 149                      ? $jsonErrors[$last]
 150                      : 'Unknown error')
 151              );
 152          }
 153   
 154          return $data;
 155      }
 156   
 157      /**
 158       * Get the default User-Agent string to use with Guzzle
 159       *
 160       * @return string
 161       */
 162      public static function getDefaultUserAgent()
 163      {
 164          static $defaultAgent = '';
 165          if (!$defaultAgent) {
 166              $defaultAgent = 'Guzzle/' . ClientInterface::VERSION;
 167              if (extension_loaded('curl')) {
 168                  $defaultAgent .= ' curl/' . curl_version()['version'];
 169              }
 170              $defaultAgent .= ' PHP/' . PHP_VERSION;
 171          }
 172   
 173          return $defaultAgent;
 174      }
 175   
 176      /**
 177       * Create a default handler to use based on the environment
 178       *
 179       * @throws \RuntimeException if no viable Handler is available.
 180       */
 181      public static function getDefaultHandler()
 182      {
 183          $default = $future = null;
 184   
 185          if (extension_loaded('curl')) {
 186              $config = [
 187                  'select_timeout' => getenv('GUZZLE_CURL_SELECT_TIMEOUT') ?: 1
 188              ];
 189              if ($maxHandles = getenv('GUZZLE_CURL_MAX_HANDLES')) {
 190                  $config['max_handles'] = $maxHandles;
 191              }
 192              if (function_exists('curl_reset')) {
 193                  $default = new CurlHandler();
 194                  $future = new CurlMultiHandler($config);
 195              } else {
 196                  $default = new CurlMultiHandler($config);
 197              }
 198          }
 199   
 200          if (ini_get('allow_url_fopen')) {
 201              $default = !$default
 202                  ? new StreamHandler()
 203                  : Middleware::wrapStreaming($default, new StreamHandler());
 204          } elseif (!$default) {
 205              throw new \RuntimeException('Guzzle requires cURL, the '
 206                  . 'allow_url_fopen ini setting, or a custom HTTP handler.');
 207          }
 208   
 209          return $future ? Middleware::wrapFuture($default, $future) : $default;
 210      }
 211  }
 212