Changeset View
Changeset View
Standalone View
Standalone View
src/applications/repository/storage/PhabricatorRepositoryURI.php
Show First 20 Lines • Show All 187 Lines • ▼ Show 20 Lines | if ($this->isBuiltin()) { | ||||
} | } | ||||
} | } | ||||
return self::IO_NONE; | return self::IO_NONE; | ||||
} | } | ||||
public function getDisplayURI() { | public function getDisplayURI() { | ||||
$uri = new PhutilURI($this->getURI()); | return $this->getURIObject(false); | ||||
} | |||||
public function getEffectiveURI() { | |||||
return $this->getURIObject(true); | |||||
} | |||||
private function getURIObject($normalize) { | |||||
// Users can provide Git/SCP-style URIs in the form "user@host:path". | |||||
// These are equivalent to "ssh://user@host/path". We use the more standard | |||||
// form internally, and convert to it if we need to specify a port number, | |||||
// but try to preserve what the user typed when displaying the URI. | |||||
if ($this->isBuiltin()) { | |||||
$builtin_protocol = $this->getForcedProtocol(); | |||||
$builtin_domain = $this->getForcedHost(); | |||||
$raw_uri = "{$builtin_protocol}://{$builtin_domain}"; | |||||
} else { | |||||
$raw_uri = $this->getURI(); | |||||
} | |||||
$port = $this->getForcedPort(); | |||||
$default_ports = array( | |||||
'ssh' => 22, | |||||
'http' => 80, | |||||
'https' => 443, | |||||
); | |||||
$uri = new PhutilURI($raw_uri); | |||||
if (!$uri->getProtocol()) { | |||||
$git_uri = new PhutilGitURI($raw_uri); | |||||
// We must normalize this Git-style URI into a normal URI | |||||
$must_normalize = ($port && ($port != $default_ports['ssh'])); | |||||
if ($must_normalize || $normalize) { | |||||
$domain = $git_uri->getDomain(); | |||||
$uri = id(new PhutilURI("ssh://{$domain}")) | |||||
->setUser($git_uri->getUser()) | |||||
->setPath($git_uri->getPath()); | |||||
} else { | |||||
$uri = $git_uri; | |||||
} | |||||
} | |||||
$is_normal = ($uri instanceof PhutilURI); | |||||
if ($is_normal) { | |||||
$protocol = $this->getForcedProtocol(); | $protocol = $this->getForcedProtocol(); | ||||
if ($protocol) { | if ($protocol) { | ||||
$uri->setProtocol($protocol); | $uri->setProtocol($protocol); | ||||
} | } | ||||
if ($port) { | |||||
$uri->setPort($port); | |||||
} | |||||
// Remove any explicitly set default ports. | |||||
$uri_port = $uri->getPort(); | |||||
$uri_protocol = $uri->getProtocol(); | |||||
$uri_default = idx($default_ports, $uri_protocol); | |||||
if ($uri_default && ($uri_default == $uri_port)) { | |||||
$uri->setPort(null); | |||||
} | |||||
} | |||||
$user = $this->getForcedUser(); | $user = $this->getForcedUser(); | ||||
if ($user) { | if ($user) { | ||||
$uri->setUser($user); | $uri->setUser($user); | ||||
} | } | ||||
$host = $this->getForcedHost(); | $host = $this->getForcedHost(); | ||||
if ($host) { | if ($host) { | ||||
$uri->setDomain($host); | $uri->setDomain($host); | ||||
} | } | ||||
$port = $this->getForcedPort(); | |||||
if ($port) { | |||||
$uri->setPort($port); | |||||
} | |||||
$path = $this->getForcedPath(); | $path = $this->getForcedPath(); | ||||
if ($path) { | if ($path) { | ||||
$uri->setPath($path); | $uri->setPath($path); | ||||
} | } | ||||
return $uri; | return $uri; | ||||
} | } | ||||
private function getForcedProtocol() { | private function getForcedProtocol() { | ||||
switch ($this->getBuiltinProtocol()) { | switch ($this->getBuiltinProtocol()) { | ||||
case self::BUILTIN_PROTOCOL_SSH: | case self::BUILTIN_PROTOCOL_SSH: | ||||
return 'ssh'; | return 'ssh'; | ||||
case self::BUILTIN_PROTOCOL_HTTP: | case self::BUILTIN_PROTOCOL_HTTP: | ||||
return 'http'; | return 'http'; | ||||
case self::BUILTIN_PROTOCOL_HTTPS: | case self::BUILTIN_PROTOCOL_HTTPS: | ||||
return 'https'; | return 'https'; | ||||
▲ Show 20 Lines • Show All 207 Lines • ▼ Show 20 Lines | return array( | ||||
'label' => pht('Hidden'), | 'label' => pht('Hidden'), | ||||
'note' => pht( | 'note' => pht( | ||||
'This URI will be hidden from users.'), | 'This URI will be hidden from users.'), | ||||
'short' => pht('Do not show as a clone URI.'), | 'short' => pht('Do not show as a clone URI.'), | ||||
), | ), | ||||
); | ); | ||||
} | } | ||||
public function newCommandEngine() { | |||||
$repository = $this->getRepository(); | |||||
$protocol = $this->getEffectiveURI()->getProtocol(); | |||||
return DiffusionCommandEngine::newCommandEngine($repository) | |||||
->setCredentialPHID($this->getCredentialPHID()) | |||||
->setProtocol($protocol); | |||||
} | |||||
/* -( PhabricatorApplicationTransactionInterface )------------------------- */ | /* -( PhabricatorApplicationTransactionInterface )------------------------- */ | ||||
public function getApplicationTransactionEditor() { | public function getApplicationTransactionEditor() { | ||||
return new DiffusionURIEditor(); | return new DiffusionURIEditor(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 107 Lines • ▼ Show 20 Lines | public function getFieldSpecificationsForConduit() { | ||||
); | ); | ||||
} | } | ||||
public function getFieldValuesForConduit() { | public function getFieldValuesForConduit() { | ||||
return array( | return array( | ||||
'repositoryPHID' => $this->getRepositoryPHID(), | 'repositoryPHID' => $this->getRepositoryPHID(), | ||||
'uri' => array( | 'uri' => array( | ||||
'raw' => $this->getURI(), | 'raw' => $this->getURI(), | ||||
'effective' => (string)$this->getDisplayURI(), | 'display' => (string)$this->getDisplayURI(), | ||||
'effective' => (string)$this->getEffectiveURI(), | |||||
), | ), | ||||
'io' => array( | 'io' => array( | ||||
'raw' => $this->getIOType(), | 'raw' => $this->getIOType(), | ||||
'default' => $this->getDefaultIOType(), | 'default' => $this->getDefaultIOType(), | ||||
'effective' => $this->getEffectiveIOType(), | 'effective' => $this->getEffectiveIOType(), | ||||
), | ), | ||||
'display' => array( | 'display' => array( | ||||
'raw' => $this->getDisplayType(), | 'raw' => $this->getDisplayType(), | ||||
Show All 19 Lines |