Skip to content
This repository has been archived by the owner on Mar 28, 2021. It is now read-only.

Commit

Permalink
Improve SERVER_PORT fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Mar 6, 2017
1 parent 77e636b commit b06c830
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@

All Notable changes to `League\Uri\Components` will be documented in this file

## 1.0.3 - TBD

### Added

- None

### Fixed

- Bug fix `$_SERVER['SERVER_PORT']` valui with `League\Uri\Schemes\Http::createFromServer` see [#PR1](https://github.com/thephpleague/uri-schemes/pull/1)

### Deprecated

- None

### Removed

- None

## 1.0.2 - 2017-03-01

### Added
Expand Down
6 changes: 4 additions & 2 deletions src/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ public static function createFromServer(array $server): self
list($host, $port) = static::fetchHostname($server);
list($path, $query) = static::fetchRequestUri($server);

$port = $port !== null ? (int) $port : $port;

return new static(static::fetchScheme($server), $user, $pass, $host, $port, $path, $query);
}

Expand Down Expand Up @@ -130,6 +128,10 @@ protected static function fetchUserInfo(array $server): array
protected static function fetchHostname(array $server): array
{
$server += ['SERVER_PORT' => null];
if (null !== $server['SERVER_PORT']) {
$server['SERVER_PORT'] = (int) $server['SERVER_PORT'];
}

if (isset($server['HTTP_HOST'])) {
preg_match(',^(?<host>(\[.*\]|[^:])*)(\:(?<port>[^/?\#]*))?$,x', $server['HTTP_HOST'], $matches);

Expand Down
2 changes: 1 addition & 1 deletion tests/HttpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public function validServerArray()
'REQUEST_URI' => '',
'SERVER_ADDR' => '127.0.0.1',
'HTTPS' => 'on',
'SERVER_PORT' => 23,
'SERVER_PORT' => '23',
'HTTP_HOST' => 'example.com',
],
],
Expand Down

0 comments on commit b06c830

Please sign in to comment.