diff --git a/CHANGELOG.md b/CHANGELOG.md index 02c07da..7831282 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,17 @@ # Change Log -## 1.5.2 - 2023-05-23 +## 1.6.0 - 2023-05-21 + +### Fixed + +- We actually did fallback to the legacy message factory discovery so 1.5.2 is broken. + Changed to use PSR 17 factory discovery. + If you allow the composer plugin of `php-http/discovery`, things will work out of the box. + When disabled and you do not have a PSR-17 factory installed, you will need to explicitly require one, e.g. `nyholm/psr7`. + +## 1.5.2 - 2023-05-17 + +**Broken, use 1.6.0 instead** ### Removed diff --git a/composer.json b/composer.json index c9ded2b..4fe07ad 100644 --- a/composer.json +++ b/composer.json @@ -18,10 +18,10 @@ "require": { "php": "^7.1 || ^8.0", "php-http/client-common": "^2.0", - "php-http/discovery": "^1.0", + "php-http/discovery": "^1.16", "php-http/httplug": "^2.0", "psr/http-client": "^1.0", - "psr/http-factory": "^1.0", + "psr/http-factory-implementation": "^1.0", "psr/http-message": "^1.0 || ^2.0", "symfony/polyfill-php80": "^1.17" }, @@ -34,7 +34,10 @@ "phpspec/phpspec": "^5.1 || ^6.1 || ^7.3" }, "config": { - "sort-packages": true + "sort-packages": true, + "allow-plugins": { + "php-http/discovery": true + } }, "autoload": { "psr-4": { diff --git a/spec/ClientSpec.php b/spec/ClientSpec.php index 4040d3d..7b88db0 100644 --- a/spec/ClientSpec.php +++ b/spec/ClientSpec.php @@ -22,6 +22,9 @@ function let(ResponseFactoryInterface $responseFactory) function it_is_initializable() { $this->shouldHaveType(Client::class); + + // make sure the client is also instantiable without arguments + new Client(); } function it_is_an_http_client() diff --git a/src/Client.php b/src/Client.php index e10890a..c572a28 100644 --- a/src/Client.php +++ b/src/Client.php @@ -6,7 +6,9 @@ use Http\Client\Exception; use Http\Client\HttpAsyncClient; use Http\Client\HttpClient; +use Http\Discovery\Exception\NotFoundException; use Http\Discovery\MessageFactoryDiscovery; +use Http\Discovery\Psr17FactoryDiscovery; use Http\Message\RequestMatcher; use Http\Message\ResponseFactory; use Psr\Http\Client\ClientExceptionInterface; @@ -72,7 +74,21 @@ public function __construct($responseFactory = null) ); } - $this->responseFactory = $responseFactory ?: MessageFactoryDiscovery::find(); + if ($responseFactory) { + $this->responseFactory = $responseFactory; + + return; + } + try { + $this->responseFactory = Psr17FactoryDiscovery::findResponseFactory(); + } catch (NotFoundException $notFoundException) { + try { + $this->responseFactory = MessageFactoryDiscovery::find(); + } catch (NotFoundException $e) { + // throw the psr-17 exception to make people install the new way and not the old + throw $notFoundException; + } + } } /**