Skip to content
This repository was archived by the owner on Sep 22, 2025. It is now read-only.

Commit 6b4afdb

Browse files
committed
Improve constructor
1 parent 65e253e commit 6b4afdb

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/Rfc3986/Uri.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function __construct(string $uri, ?string $baseUri = null)
5858

5959
try {
6060
$uri = null !== $baseUri ? UriString::resolve($uri, $baseUri) : $uri;
61-
$components = UriString::parse($uri);
61+
$components = self::addUserInfo(UriString::parse($uri));
6262
} catch (Exception $exception) {
6363
throw new InvalidUriException($exception->getMessage(), previous: $exception);
6464
}
@@ -70,7 +70,7 @@ public function __construct(string $uri, ?string $baseUri = null)
7070
Encoder::isFragmentEncoded($components['fragment']) || throw new InvalidUriException('The encoded fragment string component `'.$components['fragment'].'` contains invalid characters.');
7171

7272
$this->rawUri = $uri;
73-
$this->rawComponents = self::addUserInfo($components);
73+
$this->rawComponents = $components;
7474
}
7575

7676
/**
@@ -140,13 +140,15 @@ private function getComponent(string $type, string $name): ?string
140140

141141
private function setNormalizedComponents(): void
142142
{
143-
if (!$this->isNormalized) {
144-
$this->normalizedComponents = [
145-
...self::addUserInfo(UriString::parseNormalized($this->rawUri)),
146-
...['host' => Encoder::normalizeHost($this->rawComponents['host'])],
147-
];
148-
$this->isNormalized = true;
143+
if ($this->isNormalized) {
144+
return;
149145
}
146+
147+
$this->normalizedComponents = [
148+
...self::addUserInfo(UriString::parseNormalized($this->rawUri)),
149+
...['host' => Encoder::normalizeHost($this->rawComponents['host'])],
150+
];
151+
$this->isNormalized = true;
150152
}
151153

152154
/**

0 commit comments

Comments
 (0)