Skip to content

Commit d598e78

Browse files
committed
prefer psr 17 factory discovery
1 parent 7d046f4 commit d598e78

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

CHANGELOG.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
# Change Log
22

3-
## 1.5.2 - 2023-05-23
3+
## 1.6.0 - 2023-05-21
4+
5+
### Fixed
6+
7+
- We actually did fallback to the legacy message factory discovery so 1.5.2 is broken.
8+
Changed to use PSR 17 factory discovery.
9+
If you allow the composer plugin of `php-http/discovery`, things will work out of the box.
10+
When disabled and you do not have a PSR-17 factory installed, you will need to explicitly require one, e.g. `nyholm/psr7`.
11+
12+
## 1.5.2 - 2023-05-17
13+
14+
**Broken, use 1.6.0 instead**
415

516
### Removed
617

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"config": {
3737
"sort-packages": true,
3838
"allow-plugins": {
39-
"php-http/discovery": true
39+
"php-http/discovery": false
4040
}
4141
},
4242
"autoload": {

src/Client.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Http\Client\Exception;
77
use Http\Client\HttpAsyncClient;
88
use Http\Client\HttpClient;
9+
use Http\Discovery\Exception\NotFoundException;
910
use Http\Discovery\MessageFactoryDiscovery;
1011
use Http\Discovery\Psr17FactoryDiscovery;
1112
use Http\Message\RequestMatcher;
@@ -73,7 +74,21 @@ public function __construct($responseFactory = null)
7374
);
7475
}
7576

76-
$this->responseFactory = $responseFactory ?: Psr17FactoryDiscovery::findResponseFactory();
77+
if ($responseFactory) {
78+
$this->responseFactory = $responseFactory;
79+
80+
return;
81+
}
82+
try {
83+
$this->responseFactory = Psr17FactoryDiscovery::findResponseFactory();
84+
} catch (NotFoundException $notFoundException) {
85+
try {
86+
$this->responseFactory = MessageFactoryDiscovery::find();
87+
} catch (NotFoundException $e) {
88+
// throw the psr-17 exception to make people install the new way and not the old
89+
throw $notFoundException;
90+
}
91+
}
7792
}
7893

7994
/**

0 commit comments

Comments
 (0)