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

Commit

Permalink
bugfix Factory::create
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Mar 14, 2018
1 parent edd5ab5 commit c26aeda
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ when the `intl` extension is missing or the ICU minimum version is not supported
### Fixed

- `Factory::create` now always remove dot segments
- `Factory::create` create with a relative path
- Using PHPstan
- Improve Host parsing according to RFC3986
- Improve Parsing performance
Expand Down
12 changes: 10 additions & 2 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,21 @@ protected function getClassName($scheme, $base_uri = null): string
*/
protected function newInstance(array $components, string $className)
{
return (new ReflectionClass($className))
$uri = (new ReflectionClass($className))
->newInstanceWithoutConstructor()
->withHost($components['host'] ?? '')
->withPort($components['port'] ?? null)
->withUserInfo($components['user'] ?? '', $components['pass'] ?? null)
->withScheme($components['scheme'] ?? '')
->withPath($components['path'] ?? '')
;

$path = $components['path'] ?? '';
if ('' !== $uri->getAuthority() && '' !== $path && '/' !== $path[0]) {
$path = '/'.$path;
}

return $uri
->withPath($path)
->withQuery($components['query'] ?? '')
->withFragment($components['fragment'] ?? '')
;
Expand Down
6 changes: 6 additions & 0 deletions tests/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@ public function uriBaseUriProvider()
'uri' => 'https://EXAMPLE.com/../x',
'base_uri' => null,
],
'relative path with absolute path' => [
'expected_class' => Uri\File::class,
'expected_uri' => 'file://localhost/',
'uri' => '..',
'base_uri' => 'file://C:/demo',
],
];
}

Expand Down

0 comments on commit c26aeda

Please sign in to comment.