Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0d90c47

Browse files
[HttpClient] use "nyholm/psr7" by default in Psr18Client
1 parentc30f462 commit0d90c47

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

‎src/Symfony/Component/HttpClient/Psr18Client.php‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespaceSymfony\Component\HttpClient;
1313

14+
useNyholm\Psr7\Factory\Psr17Factory;
1415
usePsr\Http\Client\ClientInterface;
1516
usePsr\Http\Client\NetworkExceptionInterface;
1617
usePsr\Http\Client\RequestExceptionInterface;
@@ -21,6 +22,10 @@
2122
useSymfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
2223
useSymfony\Contracts\HttpClient\HttpClientInterface;
2324

25+
if (!interface_exists(ClientInterface::class)) {
26+
thrownew \LogicException('You cannot use the "Symfony\Component\HttpClient\Psr18Client" as the "psr/http-client" package is not installed. Try running "composer require psr/http-client".');
27+
}
28+
2429
/**
2530
* An adapter to turn a Symfony HttpClientInterface into a PSR-18 ClientInterface.
2631
*
@@ -38,11 +43,23 @@ final class Psr18Client implements ClientInterface
3843
private$responseFactory;
3944
private$streamFactory;
4045

41-
publicfunction__construct(HttpClientInterface$client,ResponseFactoryInterface$responseFactory,StreamFactoryInterface$streamFactory)
46+
publicfunction__construct(HttpClientInterface$client,ResponseFactoryInterface$responseFactory =null,StreamFactoryInterface$streamFactory =null)
4247
{
4348
$this->client =$client;
4449
$this->responseFactory =$responseFactory;
45-
$this->streamFactory =$streamFactory;
50+
$this->streamFactory =$streamFactory ?? ($responseFactoryinstanceof StreamFactoryInterface ?$responseFactory :null);
51+
52+
if (null !==$this->responseFactory &&null !==$this->streamFactory) {
53+
return;
54+
}
55+
56+
if (!class_exists(Psr17Factory::class)) {
57+
thrownew \LogicException('You cannot use the "Symfony\Component\HttpClient\Psr18Client" as no PSR-17 factories have been provided. Try running "composer require nyholm/psr7".');
58+
}
59+
60+
$psr17Factory =newPsr17Factory();
61+
$this->responseFactory =$this->responseFactory ??$psr17Factory;
62+
$this->streamFactory =$this->streamFactory ??$psr17Factory;
4663
}
4764

4865
publicfunctionsendRequest(RequestInterface$request):ResponseInterface

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp