From f4883acb3ca6a663f1c4c14f440a6352ec1417bb Mon Sep 17 00:00:00 2001 From: otsch Date: Wed, 28 Jun 2023 16:36:26 +0200 Subject: [PATCH] Support psr/http-message 2.0 --- CHANGELOG.md | 4 ++++ composer.json | 2 +- src/Psr/Uri.php | 20 ++++++++------------ 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 786411c..7362c7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [2.0.4] - 2023-06-28 +### Fixed +- Support psr/http-message v2.0. + ## [2.0.3] - 2023-01-30 ### Fixed - As there is the new query string package, replace the last usage of the `Helpers::queryStringToArray()` method with the `Query` class from the package, to not have duplicate logic. Also, the package already contains some fixes. diff --git a/composer.json b/composer.json index f29d917..d857acd 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,7 @@ }, "require": { "php" : "^8.0", - "psr/http-message": "^1.0", + "psr/http-message": "^1.0 || ^2.0", "symfony/polyfill-intl-idn": "^1.11", "crwlr/query-string": "^1.0" }, diff --git a/src/Psr/Uri.php b/src/Psr/Uri.php index 6f86eb2..8644edc 100644 --- a/src/Psr/Uri.php +++ b/src/Psr/Uri.php @@ -105,9 +105,9 @@ public function getFragment(): string * @throws Exception * @throws InvalidArgumentException */ - public function withScheme($scheme): Uri + public function withScheme(string $scheme): Uri { - if (!is_string($scheme) || (!Validator::scheme($scheme) && trim($scheme) !== '')) { + if ((!Validator::scheme($scheme) && trim($scheme) !== '')) { throw new InvalidArgumentException('Invalid scheme.'); } @@ -120,7 +120,7 @@ public function withScheme($scheme): Uri * @return Uri * @throws Exception */ - public function withUserInfo($user, $password = null): Uri + public function withUserInfo(string $user, ?string $password = null): Uri { $newUrl = $this->newUrlInstance(); $newUrl->user($user); @@ -134,7 +134,7 @@ public function withUserInfo($user, $password = null): Uri * @return Uri * @throws Exception */ - public function withHost($host): Uri + public function withHost(string $host): Uri { $newUrl = $this->newUrlInstance(); $newUrl->host($host); @@ -148,7 +148,7 @@ public function withHost($host): Uri * @throws Exception * @throws InvalidArgumentException */ - public function withPort($port): Uri + public function withPort(?int $port): Uri { if ($port !== null && Validator::port($port) === null) { throw new InvalidArgumentException('Port is outside the valid TCP and UDP port ranges.'); @@ -173,14 +173,10 @@ public function withPort($port): Uri * @return Uri * @throws Exception */ - public function withPath($path): Uri + public function withPath(string $path): Uri { $newUrl = $this->newUrlInstance(); - if (!is_string($path)) { - $path = ''; - } - if (!str_starts_with($path, '/') && trim($path) !== '') { $path = $this->resolver->resolvePath($path, $this->url->path() ?? ''); } @@ -195,7 +191,7 @@ public function withPath($path): Uri * @return Uri * @throws Exception */ - public function withQuery($query): Uri + public function withQuery(string $query): Uri { $newUrl = $this->newUrlInstance(); $newUrl->query($query); @@ -208,7 +204,7 @@ public function withQuery($query): Uri * @return Uri * @throws Exception */ - public function withFragment($fragment): Uri + public function withFragment(string $fragment): Uri { $newUrl = $this->newUrlInstance(); $newUrl->fragment($fragment);