Skip to content

Commit

Permalink
use non-deprecated methods with league/uri 7 (#369)
Browse files Browse the repository at this point in the history
  • Loading branch information
xabbuh authored Dec 13, 2024
1 parent f607a33 commit 6cac9e1
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
24 changes: 17 additions & 7 deletions src/Connection/Internal/Http2ConnectionProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -647,13 +647,23 @@ public function handlePushPromise(int $streamId, int $pushId, array $pseudo, arr
}

try {
$uri = Uri\Http::createFromComponents([
"scheme" => $scheme,
"host" => $host,
"port" => $port,
"path" => $target,
"query" => $query,
]);
if (\method_exists(Uri\Http::class, 'fromComponents')) {
$uri = Uri\Http::fromComponents([
"scheme" => $scheme,
"host" => $host,
"port" => $port,
"path" => $target,
"query" => $query,
]);
} else {
$uri = Uri\Http::createFromComponents([
"scheme" => $scheme,
"host" => $host,
"port" => $port,
"path" => $target,
"query" => $query,
]);
}
} catch (\Exception $exception) {
$this->handleConnectionException(new Http2ConnectionException(
"Invalid push URI",
Expand Down
6 changes: 5 additions & 1 deletion src/Interceptor/FollowRedirects.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,11 @@ private function getRedirectUri(Response $response): ?PsrUri
$location = $response->getHeader('location');
\assert($location !== null);

$locationUri = Uri\Http::createFromString($location);
if (\method_exists(Uri\Http::class, 'new')) {
$locationUri = Uri\Http::new($location);
} else {
$locationUri = Uri\Http::createFromString($location);
}
} catch (\Exception $e) {
return null;
}
Expand Down
6 changes: 5 additions & 1 deletion src/Interceptor/MatchOrigin.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ public function request(
private function checkOrigin(string $origin): string
{
try {
$originUri = Http::createFromString($origin);
if (\method_exists(Http::class, 'new')) {
$originUri = Http::new($origin);
} else {
$originUri = Http::createFromString($origin);
}
} catch (\Exception $e) {
throw new HttpException("Invalid origin provided: parsing failed: " . $origin);
}
Expand Down
4 changes: 4 additions & 0 deletions src/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,10 @@ public function isIdempotent(): bool

private function createUriFromString(string $uri): UriInterface
{
if (\method_exists(Uri\Http::class, 'new')) {
return Uri\Http::new($uri);
}

return Uri\Http::createFromString($uri);
}
}

0 comments on commit 6cac9e1

Please sign in to comment.