Skip to content

Commit

Permalink
Improve BaseUri implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Jul 30, 2023
1 parent e1d8d33 commit fdbabbd
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions BaseUri.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,34 +57,34 @@ private function __construct(
private function computeOrigin(Psr7UriInterface|UriInterface $uri, ?string $nullValue): Psr7UriInterface|UriInterface|null
{
$scheme = $uri->getScheme();
if ('blob' === $scheme) {
$components = UriString::parse($uri->getPath());
if ($uri instanceof Psr7UriInterface) {
/** @var ComponentMap $components */
$components = array_map(fn ($component) => null === $component ? '' : $component, $components);
}
if ('blob' !== $scheme) {
return match (true) {
isset(self::WHATWG_SPECIAL_SCHEMES[$scheme]) => $uri
->withFragment($nullValue)
->withQuery($nullValue)
->withPath('')
->withUserInfo($nullValue),
default => null,
};
}

$components = UriString::parse($uri->getPath());
if ($uri instanceof Psr7UriInterface) {
/** @var ComponentMap $components */
$components = array_map(fn ($component) => null === $component ? '' : $component, $components);
}

$uri = $uri
return match (true) {
null !== $components['scheme'] && isset(self::WHATWG_SPECIAL_SCHEMES[strtolower($components['scheme'])]) => $uri
->withFragment($this->nullValue)
->withQuery($this->nullValue)
->withPath('')
->withHost($components['host'])
->withPort($components['port'])
->withScheme($components['scheme'])
->withUserInfo($this->nullValue);

$scheme = $uri->getScheme();
}

if (!isset(self::WHATWG_SPECIAL_SCHEMES[$scheme])) {
return null;
}

return $uri
->withFragment($nullValue)
->withQuery($nullValue)
->withPath('')
->withUserInfo($nullValue);
->withUserInfo($this->nullValue),
default => null,
};
}

public static function from(Stringable|string $uri, UriFactoryInterface|null $uriFactory = null): self
Expand Down

0 comments on commit fdbabbd

Please sign in to comment.