Verzeichnisstruktur phpBB-3.3.16


Veröffentlicht
27.04.2026

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

Uri.php

Zuletzt modifiziert: 01.05.2026, 11:29 - Dateigröße: 8.30 KiB


 001  <?php
 002   
 003  namespace OAuth\Common\Http\Uri;
 004   
 005  use InvalidArgumentException;
 006   
 007  /**
 008   * Standards-compliant URI class.
 009   */
 010  class Uri implements UriInterface
 011  {
 012      /**
 013       * @var string
 014       */
 015      private $scheme = 'http';
 016   
 017      /**
 018       * @var string
 019       */
 020      private $userInfo = '';
 021   
 022      /**
 023       * @var string
 024       */
 025      private $rawUserInfo = '';
 026   
 027      /**
 028       * @var string
 029       */
 030      private $host;
 031   
 032      /**
 033       * @var int
 034       */
 035      private $port = 80;
 036   
 037      /**
 038       * @var string
 039       */
 040      private $path = '/';
 041   
 042      /**
 043       * @var string
 044       */
 045      private $query = '';
 046   
 047      /**
 048       * @var string
 049       */
 050      private $fragment = '';
 051   
 052      /**
 053       * @var bool
 054       */
 055      private $explicitPortSpecified = false;
 056   
 057      /**
 058       * @var bool
 059       */
 060      private $explicitTrailingHostSlash = false;
 061   
 062      /**
 063       * @param string $uri
 064       */
 065      public function __construct($uri = null)
 066      {
 067          if (null !== $uri) {
 068              $this->parseUri($uri);
 069          }
 070      }
 071   
 072      /**
 073       * @param string $uri
 074       */
 075      protected function parseUri($uri): void
 076      {
 077          if (false === ($uriParts = parse_url($uri))) {
 078              // congratulations if you've managed to get parse_url to fail,
 079              // it seems to always return some semblance of a parsed url no matter what
 080              throw new InvalidArgumentException("Invalid URI: $uri");
 081          }
 082   
 083          if (!isset($uriParts['scheme'])) {
 084              throw new InvalidArgumentException('Invalid URI: http|https scheme required');
 085          }
 086   
 087          $this->scheme = $uriParts['scheme'];
 088          $this->host = $uriParts['host'];
 089   
 090          if (isset($uriParts['port'])) {
 091              $this->port = $uriParts['port'];
 092              $this->explicitPortSpecified = true;
 093          } else {
 094              $this->port = strcmp('https', $uriParts['scheme']) ? 80 : 443;
 095              $this->explicitPortSpecified = false;
 096          }
 097   
 098          if (isset($uriParts['path'])) {
 099              $this->path = $uriParts['path'];
 100              if ('/' === $uriParts['path']) {
 101                  $this->explicitTrailingHostSlash = true;
 102              }
 103          } else {
 104              $this->path = '/';
 105          }
 106   
 107          $this->query = $uriParts['query'] ?? '';
 108          $this->fragment = $uriParts['fragment'] ?? '';
 109   
 110          $userInfo = '';
 111          if (!empty($uriParts['user'])) {
 112              $userInfo .= $uriParts['user'];
 113          }
 114          if ($userInfo && !empty($uriParts['pass'])) {
 115              $userInfo .= ':' . $uriParts['pass'];
 116          }
 117   
 118          $this->setUserInfo($userInfo);
 119      }
 120   
 121      /**
 122       * @param string $rawUserInfo
 123       *
 124       * @return string
 125       */
 126      protected function protectUserInfo($rawUserInfo)
 127      {
 128          $colonPos = strpos($rawUserInfo, ':');
 129   
 130          // rfc3986-3.2.1 | http://tools.ietf.org/html/rfc3986#section-3.2
 131          // "Applications should not render as clear text any data
 132          // after the first colon (":") character found within a userinfo
 133          // subcomponent unless the data after the colon is the empty string
 134          // (indicating no password)"
 135          if ($colonPos !== false && strlen($rawUserInfo) - 1 > $colonPos) {
 136              return substr($rawUserInfo, 0, $colonPos) . ':********';
 137          }
 138   
 139          return $rawUserInfo;
 140      }
 141   
 142      /**
 143       * @return string
 144       */
 145      public function getScheme()
 146      {
 147          return $this->scheme;
 148      }
 149   
 150      /**
 151       * @return string
 152       */
 153      public function getUserInfo()
 154      {
 155          return $this->userInfo;
 156      }
 157   
 158      /**
 159       * @return string
 160       */
 161      public function getRawUserInfo()
 162      {
 163          return $this->rawUserInfo;
 164      }
 165   
 166      /**
 167       * @return string
 168       */
 169      public function getHost()
 170      {
 171          return $this->host;
 172      }
 173   
 174      /**
 175       * @return int
 176       */
 177      public function getPort()
 178      {
 179          return $this->port;
 180      }
 181   
 182      /**
 183       * @return string
 184       */
 185      public function getPath()
 186      {
 187          return $this->path;
 188      }
 189   
 190      /**
 191       * @return string
 192       */
 193      public function getQuery()
 194      {
 195          return $this->query;
 196      }
 197   
 198      /**
 199       * @return string
 200       */
 201      public function getFragment()
 202      {
 203          return $this->fragment;
 204      }
 205   
 206      /**
 207       * Uses protected user info by default as per rfc3986-3.2.1
 208       * Uri::getRawAuthority() is available if plain-text password information is desirable.
 209       *
 210       * @return string
 211       */
 212      public function getAuthority()
 213      {
 214          $authority = $this->userInfo ? $this->userInfo . '@' : '';
 215          $authority .= $this->host;
 216   
 217          if ($this->explicitPortSpecified) {
 218              $authority .= ":{$this->port}";
 219          }
 220   
 221          return $authority;
 222      }
 223   
 224      /**
 225       * @return string
 226       */
 227      public function getRawAuthority()
 228      {
 229          $authority = $this->rawUserInfo ? $this->rawUserInfo . '@' : '';
 230          $authority .= $this->host;
 231   
 232          if ($this->explicitPortSpecified) {
 233              $authority .= ":{$this->port}";
 234          }
 235   
 236          return $authority;
 237      }
 238   
 239      /**
 240       * @return string
 241       */
 242      public function getAbsoluteUri()
 243      {
 244          $uri = $this->scheme . '://' . $this->getRawAuthority();
 245   
 246          if ('/' === $this->path) {
 247              $uri .= $this->explicitTrailingHostSlash ? '/' : '';
 248          } else {
 249              $uri .= $this->path;
 250          }
 251   
 252          if (!empty($this->query)) {
 253              $uri .= "?{$this->query}";
 254          }
 255   
 256          if (!empty($this->fragment)) {
 257              $uri .= "#{$this->fragment}";
 258          }
 259   
 260          return $uri;
 261      }
 262   
 263      /**
 264       * @return string
 265       */
 266      public function getRelativeUri()
 267      {
 268          $uri = '';
 269   
 270          if ('/' === $this->path) {
 271              $uri .= $this->explicitTrailingHostSlash ? '/' : '';
 272          } else {
 273              $uri .= $this->path;
 274          }
 275   
 276          return $uri;
 277      }
 278   
 279      /**
 280       * Uses protected user info by default as per rfc3986-3.2.1
 281       * Uri::getAbsoluteUri() is available if plain-text password information is desirable.
 282       *
 283       * @return string
 284       */
 285      public function __toString()
 286      {
 287          $uri = $this->scheme . '://' . $this->getAuthority();
 288   
 289          if ('/' === $this->path) {
 290              $uri .= $this->explicitTrailingHostSlash ? '/' : '';
 291          } else {
 292              $uri .= $this->path;
 293          }
 294   
 295          if (!empty($this->query)) {
 296              $uri .= "?{$this->query}";
 297          }
 298   
 299          if (!empty($this->fragment)) {
 300              $uri .= "#{$this->fragment}";
 301          }
 302   
 303          return $uri;
 304      }
 305   
 306      /**
 307       * @param $path
 308       */
 309      public function setPath($path): void
 310      {
 311          if (empty($path)) {
 312              $this->path = '/';
 313              $this->explicitTrailingHostSlash = false;
 314          } else {
 315              $this->path = $path;
 316              if ('/' === $this->path) {
 317                  $this->explicitTrailingHostSlash = true;
 318              }
 319          }
 320      }
 321   
 322      /**
 323       * @param string $query
 324       */
 325      public function setQuery($query): void
 326      {
 327          $this->query = $query;
 328      }
 329   
 330      /**
 331       * @param string $var
 332       * @param string $val
 333       */
 334      public function addToQuery($var, $val): void
 335      {
 336          if (strlen($this->query) > 0) {
 337              $this->query .= '&';
 338          }
 339          $this->query .= http_build_query([$var => $val], '', '&');
 340      }
 341   
 342      /**
 343       * @param string $fragment
 344       */
 345      public function setFragment($fragment): void
 346      {
 347          $this->fragment = $fragment;
 348      }
 349   
 350      /**
 351       * @param string $scheme
 352       */
 353      public function setScheme($scheme): void
 354      {
 355          $this->scheme = $scheme;
 356      }
 357   
 358      /**
 359       * @param string $userInfo
 360       */
 361      public function setUserInfo($userInfo): void
 362      {
 363          $this->userInfo = $userInfo ? $this->protectUserInfo($userInfo) : '';
 364          $this->rawUserInfo = $userInfo;
 365      }
 366   
 367      /**
 368       * @param int $port
 369       */
 370      public function setPort($port): void
 371      {
 372          $this->port = (int) $port;
 373   
 374          if (('https' === $this->scheme && $this->port === 443) || ('http' === $this->scheme && $this->port === 80)) {
 375              $this->explicitPortSpecified = false;
 376          } else {
 377              $this->explicitPortSpecified = true;
 378          }
 379      }
 380   
 381      /**
 382       * @param string $host
 383       */
 384      public function setHost($host): void
 385      {
 386          $this->host = $host;
 387      }
 388   
 389      /**
 390       * @return bool
 391       */
 392      public function hasExplicitTrailingHostSlash()
 393      {
 394          return $this->explicitTrailingHostSlash;
 395      }
 396   
 397      /**
 398       * @return bool
 399       */
 400      public function hasExplicitPortSpecified()
 401      {
 402          return $this->explicitPortSpecified;
 403      }
 404  }
 405