From 39f8463b890d0e1b379f5149f2c85134e9fc4d07 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Sun, 21 May 2023 10:08:36 +0200 Subject: [PATCH 1/3] test that mock client can discover a message factory --- composer.json | 5 ++++- spec/ClientSpec.php | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index c9ded2b..112683d 100644 --- a/composer.json +++ b/composer.json @@ -34,7 +34,10 @@ "phpspec/phpspec": "^5.1 || ^6.1 || ^7.3" }, "config": { - "sort-packages": true + "sort-packages": true, + "allow-plugins": { + "php-http/discovery": false + } }, "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() From 7d046f47059fc8d32ad1192bf894e9541651e5a1 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Sun, 21 May 2023 10:18:38 +0200 Subject: [PATCH 2/3] do psr17 discovery --- composer.json | 4 ++-- src/Client.php | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 112683d..6dfe455 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "php-http/discovery": "^1.0", "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" }, @@ -36,7 +36,7 @@ "config": { "sort-packages": true, "allow-plugins": { - "php-http/discovery": false + "php-http/discovery": true } }, "autoload": { diff --git a/src/Client.php b/src/Client.php index e10890a..e3e9ff0 100644 --- a/src/Client.php +++ b/src/Client.php @@ -7,6 +7,7 @@ use Http\Client\HttpAsyncClient; use Http\Client\HttpClient; use Http\Discovery\MessageFactoryDiscovery; +use Http\Discovery\Psr17FactoryDiscovery; use Http\Message\RequestMatcher; use Http\Message\ResponseFactory; use Psr\Http\Client\ClientExceptionInterface; @@ -72,7 +73,7 @@ public function __construct($responseFactory = null) ); } - $this->responseFactory = $responseFactory ?: MessageFactoryDiscovery::find(); + $this->responseFactory = $responseFactory ?: Psr17FactoryDiscovery::findResponseFactory(); } /** From b6a326a30cc326e859d0448e74620999e066738d Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Sun, 21 May 2023 10:26:34 +0200 Subject: [PATCH 3/3] prefer psr 17 factory discovery --- CHANGELOG.md | 13 ++++++++++++- composer.json | 2 +- src/Client.php | 17 ++++++++++++++++- 3 files changed, 29 insertions(+), 3 deletions(-) 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 6dfe455..4fe07ad 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "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-implementation": "^1.0", diff --git a/src/Client.php b/src/Client.php index e3e9ff0..c572a28 100644 --- a/src/Client.php +++ b/src/Client.php @@ -6,6 +6,7 @@ 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; @@ -73,7 +74,21 @@ public function __construct($responseFactory = null) ); } - $this->responseFactory = $responseFactory ?: Psr17FactoryDiscovery::findResponseFactory(); + 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; + } + } } /**