Skip to content

Commit 7081f6d

Browse files
committed
Adding support for PHP native RFC3986 URI parser
1 parent 6182722 commit 7081f6d

21 files changed

+142
-28
lines changed

components/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ All Notable changes to `League\Uri\Components` will be documented in this file
2323
- `Fragment::normalized`
2424
- `HierarchicalPath::normalized`
2525
- `Datapath::normalized`
26+
- Support for `Uri\Rfc3986\Uri`
2627

2728
### Fixed
2829

components/Components/Authority.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public static function tryNew(Stringable|string|null $uri = null): ?self
7878
/**
7979
* Create a new instance from a URI object.
8080
*/
81-
public static function fromUri(Stringable|string $uri): self
81+
public static function fromUri(\Uri\Rfc3986\Uri|Stringable|string $uri): self
8282
{
8383
$uri = self::filterUri($uri);
8484

components/Components/Component.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use League\Uri\Uri;
2323
use Psr\Http\Message\UriInterface as Psr7UriInterface;
2424
use Stringable;
25+
use Uri\Rfc3986\Uri as Rfc3986Uri;
2526

2627
use function is_bool;
2728
use function preg_match;
@@ -53,7 +54,7 @@ public function getUriComponent(): string
5354
return $this->toString();
5455
}
5556

56-
final protected static function filterUri(Stringable|string $uri): UriInterface|Psr7UriInterface
57+
final protected static function filterUri(Rfc3986Uri|Stringable|string $uri): UriInterface|Psr7UriInterface
5758
{
5859
return match (true) {
5960
$uri instanceof UriAccess => $uri->getUri(),

components/Components/DataPath.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ public static function fromFileContents(string $path, $context = null): self
222222
/**
223223
* Create a new instance from a URI object.
224224
*/
225-
public static function fromUri(Stringable|string $uri): self
225+
public static function fromUri(\Uri\Rfc3986\Uri|Stringable|string $uri): self
226226
{
227227
return self::new(Path::fromUri($uri)->toString());
228228
}

components/Components/Domain.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public static function fromLabels(Stringable|string ...$labels): self
9898
/**
9999
* Create a new instance from a URI object.
100100
*/
101-
public static function fromUri(Stringable|string $uri): self
101+
public static function fromUri(\Uri\Rfc3986\Uri|Stringable|string $uri): self
102102
{
103103
return self::new(Host::fromUri($uri));
104104
}

components/Components/Fragment.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,12 @@ public static function tryNew(Stringable|string|null $uri = null): ?self
5454
/**
5555
* Create a new instance from a URI object.
5656
*/
57-
public static function fromUri(Stringable|string $uri): self
57+
public static function fromUri(\Uri\Rfc3986\Uri|Stringable|string $uri): self
5858
{
59+
if ($uri instanceof \Uri\Rfc3986\Uri) {
60+
return new self($uri->getRawFragment());
61+
}
62+
5963
$uri = self::filterUri($uri);
6064

6165
return match (true) {

components/Components/HierarchicalPath.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public static function tryNew(Stringable|string $uri = ''): ?self
9595
/**
9696
* Create a new instance from a URI object.
9797
*/
98-
public static function fromUri(Stringable|string $uri): self
98+
public static function fromUri(\Uri\Rfc3986\Uri|Stringable|string $uri): self
9999
{
100100
return new self(Path::fromUri($uri));
101101
}

components/Components/Host.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,12 @@ public static function fromIp(Stringable|string $ip, string $version = ''): self
309309
/**
310310
* Create a new instance from a URI object.
311311
*/
312-
public static function fromUri(Stringable|string $uri): self
312+
public static function fromUri(\Uri\Rfc3986\Uri|Stringable|string $uri): self
313313
{
314+
if ($uri instanceof \Uri\Rfc3986\Uri) {
315+
return new self($uri->getRawHost());
316+
}
317+
314318
$uri = self::filterUri($uri);
315319

316320
return match (true) {

components/Components/Path.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public static function new(Stringable|string $value = ''): self
5656
}
5757

5858
/**
59-
* Create a new instance from a string.or a stringable structure or returns null on failure.
59+
* Create a new instance from a string or a stringable structure or returns null on failure.
6060
*/
6161
public static function tryNew(Stringable|string $uri = ''): ?self
6262
{
@@ -70,8 +70,12 @@ public static function tryNew(Stringable|string $uri = ''): ?self
7070
/**
7171
* Create a new instance from a URI object.
7272
*/
73-
public static function fromUri(Stringable|string $uri): self
73+
public static function fromUri(\Uri\Rfc3986\Uri|Stringable|string $uri): self
7474
{
75+
if ($uri instanceof \Uri\Rfc3986\Uri) {
76+
return self::new($uri->getRawPath());
77+
}
78+
7579
if (!$uri instanceof UriInterface) {
7680
$uri = Uri::new($uri);
7781
}

components/Components/Port.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,12 @@ public static function tryNew(Stringable|string|null $uri = null): ?self
5858
/**
5959
* Create a new instance from a URI object.
6060
*/
61-
public static function fromUri(Stringable|string $uri): self
61+
public static function fromUri(\Uri\Rfc3986\Uri|Stringable|string $uri): self
6262
{
63+
if ($uri instanceof \Uri\Rfc3986\Uri) {
64+
return new self($uri->getPort());
65+
}
66+
6367
return new self(self::filterUri($uri)->getPort());
6468
}
6569

0 commit comments

Comments
 (0)