w7corp/easywechat · error · LogicException
You cannot use the "Symfony\Component\HttpClient\Psr18Client
Error message
You cannot use the "Symfony\Component\HttpClient\Psr18Client" as no PSR-17 factories have been provided. Try running "composer require nyholm/psr7".
What it means
Response::toPsrResponse() needs PSR-17 response and stream factories. When neither is passed as an argument and neither Nyholm's Psr17Factory nor php-http/discovery's Psr17FactoryDiscovery class exists in the vendor tree, it throws LogicException telling you the PSR-18 bridge cannot be used — the fix is to install nyholm/psr7 or pass factories explicitly.
Source
Thrown at src/Kernel/HttpClient/Response.php:153
return StreamWrapper::createResource(new MockResponse);
}
/**
* @throws \LogicException
*/
public function toDataUrl(): string
{
return 'data:'.$this->getHeaderLine('content-type').';base64,'.base64_encode($this->getContent());
}
public function toPsrResponse(?ResponseFactoryInterface $responseFactory = null, ?StreamFactoryInterface $streamFactory = null): \Psr\Http\Message\ResponseInterface
{
$streamFactory ??= $responseFactory instanceof StreamFactoryInterface ? $responseFactory : null;
if ($responseFactory === null || $streamFactory === null) {
if (! class_exists(Psr17Factory::class) && ! class_exists(Psr17FactoryDiscovery::class)) {
throw new \LogicException('You cannot use the "Symfony\Component\HttpClient\Psr18Client" as no PSR-17 factories have been provided. Try running "composer require nyholm/psr7".');
}
try {
$psr17Factory = class_exists(Psr17Factory::class, false) ? new Psr17Factory : null;
$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);
}
}
$psrResponse = $responseFactory->createResponse($this->getStatusCode());
foreach ($this->getHeaders(false) as $name => $values) {
foreach ($values as $value) {
$psrResponse = $psrResponse->withAddedHeader($name, $value);View on GitHub (pinned to f0cf0a8b83)
Solutions
- composer require nyholm/psr7 — the Psr17Factory class will then be auto-detected
- Or pass factories explicitly: $response->toPsrResponse($httpFactory, $httpFactory) using any ResponseFactoryInterface+StreamFactoryInterface (e.g. Guzzle's HttpFactory)
- Verify with class_exists(\Nyholm\Psr7\Factory\Psr17Factory::class) in a smoke test if this integration matters
Example fix
// before $psr7 = $response->toPsrResponse(); // LogicException // after use GuzzleHttp\Psr7\HttpFactory; $factory = new HttpFactory(); $psr7 = $response->toPsrResponse($factory, $factory);
Defensive patterns
Strategy: validation
Validate before calling
// Verify PSR-17 availability before bridging
if ($responseFactory === null && ! class_exists(\Nyholm\Psr7\Factory\Psr17Factory::class) && ! class_exists(\Http\Discovery\Psr17FactoryDiscovery::class)) {
throw new LogicException('Install nyholm/psr7 or pass PSR-17 factories to toPsrResponse()');
}
$psr7 = $response->toPsrResponse(); Prevention
- Require nyholm/psr7 in composer if any code path calls toPsrResponse()
- Wire your framework's HTTP factory into toPsrResponse($factory, $factory) explicitly instead of relying on autoload-time discovery
When it happens
Trigger: Calling toPsrResponse() in a project that installed easywechat alone (Symfony HttpClient in, but no PSR-7/17 implementation packages present).
Common situations: Minimal dependency sets, trimming composer packages for deployment, frameworks that ship their own PSR-17 but where you forgot to hand the factories in.
Related errors
- You cannot use the "Symfony\Component\HttpClient\HttplugClie
- "%s" cannot be empty.\r\n
- -40012
- -40006
- -40001
AI-assisted analysis of w7corp/easywechat@f0cf0a8b83 (2026-08-21).
Data as JSON: /api/errors/efd75967f9a7122d.
Report an issue: GitHub.