Skip to content
This repository has been archived by the owner on Dec 31, 2022. It is now read-only.

Commit

Permalink
Merge pull request #46 from sunrise-php/release/v1.1.0
Browse files Browse the repository at this point in the history
v1.1.0
  • Loading branch information
fenric committed Apr 12, 2020
2 parents fe57c53 + 3213f49 commit dfe7db6
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 16 deletions.
3 changes: 1 addition & 2 deletions composer.json
Expand Up @@ -22,8 +22,7 @@
"psr/http-message": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "7.5.6",
"php-http/psr7-integration-tests": "dev-master"
"phpunit/phpunit": "7.5.6"
},
"provide": {
"psr/http-message-implementation": "1.0"
Expand Down
29 changes: 29 additions & 0 deletions src/Uri.php
Expand Up @@ -23,6 +23,11 @@
use Sunrise\Uri\Component\Query;
use Sunrise\Uri\Component\Fragment;

/**
* Import functions
*/
use function getservbyname;

/**
* Uniform Resource Identifier
*
Expand Down Expand Up @@ -266,6 +271,30 @@ public function getPort() : ?int
return $this->port;
}

/**
* Gets standard port number associated with the URI scheme
*
* [!] It's not PSR-7 method.
*
* @return null|int
*/
public function getStandardPort() : ?int
{
$scheme = $this->getScheme();

$servicePort = getservbyname($scheme, 'tcp');
if (false !== $servicePort) {
return $servicePort;
}

$servicePort = getservbyname($scheme, 'udp');
if (false !== $servicePort) {
return $servicePort;
}

return null;
}

/**
* {@inheritDoc}
*/
Expand Down
14 changes: 0 additions & 14 deletions tests/UriIntegrationTest.php

This file was deleted.

12 changes: 12 additions & 0 deletions tests/UriTest.php
Expand Up @@ -94,6 +94,18 @@ public function testGetFragment()
$this->assertEquals('fragment', $uri->getFragment());
}

public function testGetStandardPort() : void
{
$uri = new Uri('http://host:3000');
$this->assertEquals(80, $uri->getStandardPort());

$uri = new Uri('https://host:3000');
$this->assertEquals(443, $uri->getStandardPort());

$uri = new Uri('ftp://host:3000');
$this->assertEquals(21, $uri->getStandardPort());
}

// Withers...

public function testWithScheme()
Expand Down

0 comments on commit dfe7db6

Please sign in to comment.