Verzeichnisstruktur phpBB-3.1.0


Veröffentlicht
27.10.2014

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: 09.10.2024, 12:59 - Dateigröße: 8.18 KiB


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