public function __toString()
{
$uriString = '';
$uriString .= isset($this->scheme) ? $this->scheme . '://' : '';
if (isset($this->username)) {
if (isset($this->password)) {
$uriString .= $this->username . ':' . $this->password . '@';
} else {
$uriString .= $this->username . '@';
}
}
$uriString .= $this->host;
if ($this->port !== null) {
switch ($this->scheme) {
case 'http':
$uriString .= $this->port !== 80 ? ':' . $this->port : '';
break;
case 'https':
$uriString .= $this->port !== 443 ? ':' . $this->port : '';
break;
default:
$uriString .= isset($this->port) ? ':' . $this->port : '';
}
}
$uriString .= isset($this->path) ? $this->path : '';
$uriString .= isset($this->query) ? '?' . $this->query : '';
$uriString .= isset($this->fragment) ? '#' . $this->fragment : '';
return $uriString;
}