Пример #1
0
 /**
  * testAuthority
  *
  * @dataProvider authorityProvider
  *
  * @param string $url
  * @param string $expected
  */
 public function testAuthority($url, $expected)
 {
     $uri = new PsrUri($url);
     $this->assertEquals($expected, $uri->getAuthority());
 }
 /**
  * Marshal the URI from the $_SERVER array and headers
  *
  * @param   array  $server   The $_SERVER superglobal.
  * @param   array  $headers  The headers variable from server.
  *
  * @return  PsrUri  Prepared Uri object.
  */
 public static function prepareUri(array $server, array $headers)
 {
     $uri = new PsrUri('');
     // URI scheme
     $scheme = 'http';
     $https = ServerHelper::getValue($server, 'HTTPS');
     // Is https or not
     if ($https && $https !== 'off' || HeaderHelper::getValue($headers, 'x-forwarded-proto', false) === 'https') {
         $scheme = 'https';
     }
     // URI host
     $host = '';
     $port = null;
     static::getHostAndPortFromHeaders($host, $port, $server, $headers);
     // URI path
     $path = static::getRequestUri($server);
     $path = static::stripQueryString($path);
     // URI query
     $query = '';
     if (isset($server['QUERY_STRING'])) {
         $query = ltrim($server['QUERY_STRING'], '?');
     }
     // URI fragment
     $fragment = '';
     if (strpos($path, '#') !== false) {
         list($path, $fragment) = explode('#', $path, 2);
     }
     return $uri->withScheme($scheme)->withHost($host)->withPort($port)->withPath($path)->withFragment($fragment)->withQuery($query);
 }