Skip to content

Commit ca4fd55

Browse files
committed
First try the new interface
1 parent 63f42ea commit ca4fd55

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"php-http/message": "^1.7",
3939
"php-http/mock-client": "^1.0",
4040
"php-http/message-factory": "^1.1",
41-
"symfony/http-client": "^5.4 || ^6.4",
41+
"symfony/http-client": "^5.4 || ^6.4 || ^7.0",
4242
"nyholm/psr7": "^1.0"
4343
},
4444
"scripts": {

src/Service/HttpService.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414
namespace Exchanger\Service;
1515

1616
use Http\Client\HttpClient;
17+
use Http\Discovery\Exception\NotFoundException;
1718
use Http\Discovery\HttpClientDiscovery;
1819
use Http\Discovery\Psr17FactoryDiscovery;
20+
use Http\Discovery\Psr18ClientDiscovery;
1921
use Psr\Http\Client\ClientInterface;
2022
use Psr\Http\Message\RequestFactoryInterface;
2123
use Psr\Http\Message\RequestInterface;
@@ -50,7 +52,11 @@ abstract class HttpService extends Service
5052
public function __construct($httpClient = null, RequestFactoryInterface $requestFactory = null, array $options = [])
5153
{
5254
if (null === $httpClient) {
53-
$httpClient = HttpClientDiscovery::find();
55+
try {
56+
$httpClient = Psr18ClientDiscovery::find();
57+
} catch (NotFoundException $e) {
58+
$httpClient = HttpClientDiscovery::find();
59+
}
5460
} else {
5561
if (!$httpClient instanceof ClientInterface && !$httpClient instanceof HttpClient) {
5662
throw new \LogicException('Client must be an instance of Http\\Client\\HttpClient or Psr\\Http\\Client\\ClientInterface');

0 commit comments

Comments
 (0)