public function __construct($uri)
{
$uri = (string) $uri;
if (!($parts = $this->parse($uri))) {
throw new \DomainException('Invalid URI specified at ' . get_class($this) . '::__construct Argument 1');
}
$this->uri = $uri;
foreach ($parts as $key => $value) {
$this->{$key} = $value;
}
// http://www.apps.ietf.org/rfc/rfc3986.html#sec-3.1
// "schemes are case-insensitive"
$this->scheme = strtolower($this->scheme);
// http://www.apps.ietf.org/rfc/rfc3986.html#sec-3.2.2
// "Although host is case-insensitive, producers and normalizers should use lowercase for
// registered names and hexadecimal addresses for the sake of uniformity"
$this->host = strtolower($this->host);
if ($this->port && $this->scheme) {
$this->normalizeDefaultPort();
}
$ip = @inet_pton($this->host);
if (isset($ip[5])) {
$this->isIpV6 = true;
} elseif ($ip) {
$this->isIpv4 = true;
}
$this->parseQueryParameters();
if ($this->fragment) {
$this->fragment = rawurldecode($this->fragment);
$this->fragment = rawurlencode($this->fragment);
}
}