Changeset View
Changeset View
Standalone View
Standalone View
src/parser/PhutilURI.php
Show First 20 Lines • Show All 148 Lines • ▼ Show 20 Lines | public function __toString() { | ||||
} else { | } else { | ||||
$port = $this->port; | $port = $this->port; | ||||
} | } | ||||
$domain = $this->domain; | $domain = $this->domain; | ||||
$user = $this->user; | $user = $this->user; | ||||
$pass = $this->pass; | $pass = $this->pass; | ||||
if (strlen($user) && strlen($pass)) { | if (phutil_nonempty_string($user) && phutil_nonempty_string($pass)) { | ||||
$auth = rawurlencode($user).':'.rawurlencode($pass).'@'; | $auth = rawurlencode($user).':'.rawurlencode($pass).'@'; | ||||
} else if (strlen($user)) { | } else if (phutil_nonempty_string($user)) { | ||||
$auth = rawurlencode($user).'@'; | $auth = rawurlencode($user).'@'; | ||||
} else { | } else { | ||||
$auth = null; | $auth = null; | ||||
} | } | ||||
$protocol = $this->protocol; | $protocol = $this->protocol; | ||||
if ($this->isGitURI()) { | if ($this->isGitURI()) { | ||||
$protocol = null; | $protocol = null; | ||||
} else { | } else { | ||||
if (strlen($auth)) { | if ($auth !== null) { | ||||
$protocol = nonempty($this->protocol, 'http'); | $protocol = nonempty($this->protocol, 'http'); | ||||
} | } | ||||
} | } | ||||
if (strlen($protocol) || strlen($auth) || strlen($domain)) { | $has_protocol = ($protocol !== null) && strlen($protocol); | ||||
$has_auth = ($auth !== null); | |||||
$has_domain = ($domain !== null) && strlen($domain); | |||||
$has_port = ($port !== null) && strlen($port); | |||||
if ($has_protocol || $has_auth || $has_domain) { | |||||
if ($this->isGitURI()) { | if ($this->isGitURI()) { | ||||
$prefix = "{$auth}{$domain}"; | $prefix = "{$auth}{$domain}"; | ||||
} else { | } else { | ||||
$prefix = "{$protocol}://{$auth}{$domain}"; | $prefix = "{$protocol}://{$auth}{$domain}"; | ||||
} | } | ||||
if (strlen($port)) { | if ($has_port) { | ||||
$prefix .= ':'.$port; | $prefix .= ':'.$port; | ||||
} | } | ||||
} | } | ||||
if ($this->query) { | if ($this->query) { | ||||
$query = '?'.phutil_build_http_querystring_from_pairs($this->query); | $query = '?'.phutil_build_http_querystring_from_pairs($this->query); | ||||
} else { | } else { | ||||
$query = null; | $query = null; | ||||
} | } | ||||
if (strlen($this->getFragment())) { | if (phutil_nonempty_string($this->getFragment())) { | ||||
$fragment = '#'.$this->getFragment(); | $fragment = '#'.$this->getFragment(); | ||||
} else { | } else { | ||||
$fragment = null; | $fragment = null; | ||||
} | } | ||||
$path = $this->getPath(); | $path = $this->getPath(); | ||||
if ($this->isGitURI()) { | if ($this->isGitURI()) { | ||||
if (strlen($path)) { | if (strlen($path)) { | ||||
▲ Show 20 Lines • Show All 222 Lines • ▼ Show 20 Lines | return nonempty( | ||||
idx($default_ports, $this->getProtocol()), | idx($default_ports, $this->getProtocol()), | ||||
''); | ''); | ||||
} | } | ||||
public function setPath($path) { | public function setPath($path) { | ||||
if ($this->isGitURI()) { | if ($this->isGitURI()) { | ||||
// Git URIs use relative paths which do not need to begin with "/". | // Git URIs use relative paths which do not need to begin with "/". | ||||
} else { | } else { | ||||
if ($this->domain && strlen($path) && $path[0] !== '/') { | if ($this->domain && phutil_nonempty_string($path) && $path[0] !== '/') { | ||||
$path = '/'.$path; | $path = '/'.$path; | ||||
} | } | ||||
} | } | ||||
$this->path = $path; | $this->path = $path; | ||||
return $this; | return $this; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 120 Lines • Show Last 20 Lines |
Content licensed under Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) unless otherwise noted; code licensed under Apache 2.0 or other open source licenses. · CC BY-SA 4.0 · Apache 2.0