Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15378295
D11338.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D11338.diff
View Options
diff --git a/src/parser/PhutilURI.php b/src/parser/PhutilURI.php
--- a/src/parser/PhutilURI.php
+++ b/src/parser/PhutilURI.php
@@ -147,6 +147,19 @@
return $this->port;
}
+ public function getPortWithProtocolDefault() {
+ static $default_ports = array(
+ 'http' => '80',
+ 'https' => '443',
+ 'ssh' => '22',
+ );
+
+ return nonempty(
+ $this->getPort(),
+ idx($default_ports, $this->getProtocol()),
+ '');
+ }
+
public function setPath($path) {
if ($this->domain && strlen($path) && $path[0] !== '/') {
$path = '/'.$path;
diff --git a/src/parser/__tests__/PhutilURITestCase.php b/src/parser/__tests__/PhutilURITestCase.php
--- a/src/parser/__tests__/PhutilURITestCase.php
+++ b/src/parser/__tests__/PhutilURITestCase.php
@@ -116,4 +116,18 @@
$uri->getQueryParams());
}
+ public function testDefaultPorts() {
+ $uri = new PhutilURI('http://www.example.com');
+ $this->assertEqual('80', $uri->getPortWithProtocolDefault());
+
+ $uri = new PhutilURI('https://www.example.com');
+ $this->assertEqual('443', $uri->getPortWithProtocolDefault());
+
+ $uri = new PhutilURI('ssh://git@example.com/example/example.git');
+ $this->assertEqual('22', $uri->getPortWithProtocolDefault());
+
+ $uri = new PhutilURI('unknown://www.example.com');
+ $this->assertEqual('', $uri->getPortWithProtocolDefault());
+ }
+
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Mar 14, 1:32 PM (1 w, 1 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7658372
Default Alt Text
D11338.diff (1 KB)
Attached To
Mode
D11338: Add default ports to `PhutilURI`
Attached
Detach File
Event Timeline
Log In to Comment