From 6cac9e172a66a04df305acc8de02b6c40832b269 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Fri, 13 Dec 2024 16:50:23 +0100 Subject: [PATCH] use non-deprecated methods with league/uri 7 (#369) --- .../Internal/Http2ConnectionProcessor.php | 24 +++++++++++++------ src/Interceptor/FollowRedirects.php | 6 ++++- src/Interceptor/MatchOrigin.php | 6 ++++- src/Request.php | 4 ++++ 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/src/Connection/Internal/Http2ConnectionProcessor.php b/src/Connection/Internal/Http2ConnectionProcessor.php index 993d9c54..7f2686b4 100644 --- a/src/Connection/Internal/Http2ConnectionProcessor.php +++ b/src/Connection/Internal/Http2ConnectionProcessor.php @@ -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", diff --git a/src/Interceptor/FollowRedirects.php b/src/Interceptor/FollowRedirects.php index 31f76212..3a7b640f 100644 --- a/src/Interceptor/FollowRedirects.php +++ b/src/Interceptor/FollowRedirects.php @@ -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; } diff --git a/src/Interceptor/MatchOrigin.php b/src/Interceptor/MatchOrigin.php index 3342c4d0..80053f8e 100644 --- a/src/Interceptor/MatchOrigin.php +++ b/src/Interceptor/MatchOrigin.php @@ -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); } diff --git a/src/Request.php b/src/Request.php index 807ac8e5..46ea2aa9 100644 --- a/src/Request.php +++ b/src/Request.php @@ -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); } }