Skip to content

Commit

Permalink
增加 Response::toPsr7Response() Fixed #2476
Browse files Browse the repository at this point in the history
  • Loading branch information
overtrue committed May 23, 2022
1 parent 80ce08f commit 13d302e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"ext-libxml": "*",
"ext-curl": "*",
"monolog/monolog": "^2.2",
"nyholm/psr7": "^1.4",
"nyholm/psr7": "^1.5",
"nyholm/psr7-server": "^1.0",
"overtrue/socialite": "^3.5|^4.0.1",
"psr/simple-cache": "^1.0|^2.0|^3.0",
Expand Down
10 changes: 8 additions & 2 deletions src/Kernel/HttpClient/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@

use ArrayAccess;
use Closure;
use Http\Discovery\Exception\NotFoundException;
use Http\Discovery\Psr17FactoryDiscovery;
use EasyWeChat\Kernel\Contracts\Arrayable;
use EasyWeChat\Kernel\Contracts\Jsonable;
use EasyWeChat\Kernel\Exceptions\BadMethodCallException;
use EasyWeChat\Kernel\Exceptions\BadResponseException;
use EasyWeChat\Kernel\Support\Xml;
use Nyholm\Psr7\Factory\Psr17Factory;
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\StreamFactoryInterface;
use Symfony\Component\HttpClient\Response\MockResponse;
use Symfony\Component\HttpClient\Response\StreamableInterface;
use Symfony\Component\HttpClient\Response\StreamWrapper;
Expand Down Expand Up @@ -179,8 +183,10 @@ public function toPsrResponse(ResponseFactoryInterface $responseFactory = null,

try {
$psr17Factory = class_exists(Psr17Factory::class, false) ? new Psr17Factory() : null;
$responseFactory ??= $psr17Factory ?? Psr17FactoryDiscovery::findResponseFactory();
$streamFactory ??= $psr17Factory ?? Psr17FactoryDiscovery::findStreamFactory();
$responseFactory ??= $psr17Factory ?? Psr17FactoryDiscovery::findResponseFactory(); /** @phpstan-ignore-line */
$streamFactory ??= $psr17Factory ?? Psr17FactoryDiscovery::findStreamFactory(); /** @phpstan-ignore-line */

/** @phpstan-ignore-next-line */
} catch (NotFoundException $e) {
throw new \LogicException('You cannot use the "Symfony\Component\HttpClient\HttplugClient" as no PSR-17 factories have been found. Try running "composer require nyholm/psr7".', 0, $e);
}
Expand Down

1 comment on commit 13d302e

@vercel
Copy link

@vercel vercel bot commented on 13d302e May 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

easywechat – ./

easywechat.vercel.app
easywechat-git-6x-overtrue.vercel.app
easywechat-overtrue.vercel.app

Please sign in to comment.