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