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

UriFactory.php

Zuletzt modifiziert: 02.04.2025, 15:04 - Dateigröße: 3.91 KiB


001  <?php
002   
003  namespace OAuth\Common\Http\Uri;
004   
005  use RuntimeException;
006   
007  /**
008   * Factory class for uniform resource indicators.
009   */
010  class UriFactory implements UriFactoryInterface
011  {
012      /**
013       * Factory method to build a URI from a super-global $_SERVER array.
014       *
015       * @return UriInterface
016       */
017      public function createFromSuperGlobalArray(array $_server)
018      {
019          if ($uri = $this->attemptProxyStyleParse($_server)) {
020              return $uri;
021          }
022   
023          $scheme = $this->detectScheme($_server);
024          $host = $this->detectHost($_server);
025          $port = $this->detectPort($_server);
026          $path = $this->detectPath($_server);
027          $query = $this->detectQuery($_server);
028   
029          return $this->createFromParts($scheme, '', $host, $port, $path, $query);
030      }
031   
032      /**
033       * @param string $absoluteUri
034       *
035       * @return UriInterface
036       */
037      public function createFromAbsolute($absoluteUri)
038      {
039          return new Uri($absoluteUri);
040      }
041   
042      /**
043       * Factory method to build a URI from parts.
044       *
045       * @param string $scheme
046       * @param string $userInfo
047       * @param string $host
048       * @param string $port
049       * @param string $path
050       * @param string $query
051       * @param string $fragment
052       *
053       * @return UriInterface
054       */
055      public function createFromParts($scheme, $userInfo, $host, $port, $path = '', $query = '', $fragment = '')
056      {
057          $uri = new Uri();
058          $uri->setScheme($scheme);
059          $uri->setUserInfo($userInfo);
060          $uri->setHost($host);
061          $uri->setPort($port);
062          $uri->setPath($path);
063          $uri->setQuery($query);
064          $uri->setFragment($fragment);
065   
066          return $uri;
067      }
068   
069      /**
070       * @param array $_server
071       *
072       * @return null|UriInterface
073       */
074      private function attemptProxyStyleParse($_server)
075      {
076          // If the raw HTTP request message arrives with a proxy-style absolute URI in the
077          // initial request line, the absolute URI is stored in $_SERVER['REQUEST_URI'] and
078          // we only need to parse that.
079          if (isset($_server['REQUEST_URI']) && parse_url($_server['REQUEST_URI'], PHP_URL_SCHEME)) {
080              return new Uri($_server['REQUEST_URI']);
081          }
082   
083          return null;
084      }
085   
086      /**
087       * @param array $_server
088       *
089       * @return string
090       */
091      private function detectPath($_server)
092      {
093          if (isset($_server['REQUEST_URI'])) {
094              $uri = $_server['REQUEST_URI'];
095          } elseif (isset($_server['REDIRECT_URL'])) {
096              $uri = $_server['REDIRECT_URL'];
097          } else {
098              throw new RuntimeException('Could not detect URI path from superglobal');
099          }
100   
101          $queryStr = strpos($uri, '?');
102          if ($queryStr !== false) {
103              $uri = substr($uri, 0, $queryStr);
104          }
105   
106          return $uri;
107      }
108   
109      /**
110       * @return string
111       */
112      private function detectHost(array $_server)
113      {
114          $host = $_server['HTTP_HOST'] ?? '';
115   
116          if (strstr($host, ':')) {
117              $host = parse_url($host, PHP_URL_HOST);
118          }
119   
120          return $host;
121      }
122   
123      /**
124       * @return string
125       */
126      private function detectPort(array $_server)
127      {
128          return $_server['SERVER_PORT'] ?? 80;
129      }
130   
131      /**
132       * @return string
133       */
134      private function detectQuery(array $_server)
135      {
136          return $_server['QUERY_STRING'] ?? '';
137      }
138   
139      /**
140       * Determine URI scheme component from superglobal array.
141       *
142       * When using ISAPI with IIS, the value will be "off" if the request was
143       * not made through the HTTPS protocol. As a result, we filter the
144       * value to a bool.
145       *
146       * @param array $_server A super-global $_SERVER array
147       *
148       * @return string Returns http or https depending on the URI scheme
149       */
150      private function detectScheme(array $_server)
151      {
152          if (isset($_server['HTTPS']) && filter_var($_server['HTTPS'], FILTER_VALIDATE_BOOLEAN)) {
153              return 'https';
154          }
155   
156          return 'http';
157      }
158  }
159