Skip to content

Commit 6cac9e1

Browse files
authored
use non-deprecated methods with league/uri 7 (#369)
1 parent f607a33 commit 6cac9e1

File tree

4 files changed

+31
-9
lines changed

4 files changed

+31
-9
lines changed

src/Connection/Internal/Http2ConnectionProcessor.php

+17-7
Original file line numberDiff line numberDiff line change
@@ -647,13 +647,23 @@ public function handlePushPromise(int $streamId, int $pushId, array $pseudo, arr
647647
}
648648

649649
try {
650-
$uri = Uri\Http::createFromComponents([
651-
"scheme" => $scheme,
652-
"host" => $host,
653-
"port" => $port,
654-
"path" => $target,
655-
"query" => $query,
656-
]);
650+
if (\method_exists(Uri\Http::class, 'fromComponents')) {
651+
$uri = Uri\Http::fromComponents([
652+
"scheme" => $scheme,
653+
"host" => $host,
654+
"port" => $port,
655+
"path" => $target,
656+
"query" => $query,
657+
]);
658+
} else {
659+
$uri = Uri\Http::createFromComponents([
660+
"scheme" => $scheme,
661+
"host" => $host,
662+
"port" => $port,
663+
"path" => $target,
664+
"query" => $query,
665+
]);
666+
}
657667
} catch (\Exception $exception) {
658668
$this->handleConnectionException(new Http2ConnectionException(
659669
"Invalid push URI",

src/Interceptor/FollowRedirects.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,11 @@ private function getRedirectUri(Response $response): ?PsrUri
271271
$location = $response->getHeader('location');
272272
\assert($location !== null);
273273

274-
$locationUri = Uri\Http::createFromString($location);
274+
if (\method_exists(Uri\Http::class, 'new')) {
275+
$locationUri = Uri\Http::new($location);
276+
} else {
277+
$locationUri = Uri\Http::createFromString($location);
278+
}
275279
} catch (\Exception $e) {
276280
return null;
277281
}

src/Interceptor/MatchOrigin.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@ public function request(
6161
private function checkOrigin(string $origin): string
6262
{
6363
try {
64-
$originUri = Http::createFromString($origin);
64+
if (\method_exists(Http::class, 'new')) {
65+
$originUri = Http::new($origin);
66+
} else {
67+
$originUri = Http::createFromString($origin);
68+
}
6569
} catch (\Exception $e) {
6670
throw new HttpException("Invalid origin provided: parsing failed: " . $origin);
6771
}

src/Request.php

+4
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,10 @@ public function isIdempotent(): bool
535535

536536
private function createUriFromString(string $uri): UriInterface
537537
{
538+
if (\method_exists(Uri\Http::class, 'new')) {
539+
return Uri\Http::new($uri);
540+
}
541+
538542
return Uri\Http::createFromString($uri);
539543
}
540544
}

0 commit comments

Comments
 (0)