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