{"record":{"id":"efd75967f9a7122d","repo":"w7corp/easywechat","slug":"you-cannot-use-the-symfony-component-httpclient-p","errorCode":null,"errorMessage":"You cannot use the \"Symfony\\Component\\HttpClient\\Psr18Client\" as no PSR-17 factories have been provided. Try running \"composer require nyholm/psr7\".","messagePattern":"You cannot use the \"Symfony\\\\Component\\\\HttpClient\\\\Psr18Client\" as no PSR-17 factories have been provided\\. Try running \"composer require nyholm/psr7\"\\.","errorType":"exception","errorClass":"LogicException","httpStatus":null,"severity":"error","filePath":"src/Kernel/HttpClient/Response.php","lineNumber":153,"sourceCode":"\n        return StreamWrapper::createResource(new MockResponse);\n    }\n\n    /**\n     * @throws \\LogicException\n     */\n    public function toDataUrl(): string\n    {\n        return 'data:'.$this->getHeaderLine('content-type').';base64,'.base64_encode($this->getContent());\n    }\n\n    public function toPsrResponse(?ResponseFactoryInterface $responseFactory = null, ?StreamFactoryInterface $streamFactory = null): \\Psr\\Http\\Message\\ResponseInterface\n    {\n        $streamFactory ??= $responseFactory instanceof StreamFactoryInterface ? $responseFactory : null;\n\n        if ($responseFactory === null || $streamFactory === null) {\n            if (! class_exists(Psr17Factory::class) && ! class_exists(Psr17FactoryDiscovery::class)) {\n                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\".');\n            }\n\n            try {\n                $psr17Factory = class_exists(Psr17Factory::class, false) ? new Psr17Factory : null;\n                $responseFactory ??= $psr17Factory ?? Psr17FactoryDiscovery::findResponseFactory(); /** @phpstan-ignore-line */\n                $streamFactory ??= $psr17Factory ?? Psr17FactoryDiscovery::findStreamFactory(); /** @phpstan-ignore-line */\n\n                /** @phpstan-ignore-next-line */\n            } catch (NotFoundException $e) {\n                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);\n            }\n        }\n\n        $psrResponse = $responseFactory->createResponse($this->getStatusCode());\n\n        foreach ($this->getHeaders(false) as $name => $values) {\n            foreach ($values as $value) {\n                $psrResponse = $psrResponse->withAddedHeader($name, $value);","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/w7corp/easywechat/blob/f0cf0a8b8361417ed683b8246d0ecbaf0aafcaa8/src/Kernel/HttpClient/Response.php#L135-L171","documentation":"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.","triggerScenarios":"Calling toPsrResponse() in a project that installed easywechat alone (Symfony HttpClient in, but no PSR-7/17 implementation packages present).","commonSituations":"Minimal dependency sets, trimming composer packages for deployment, frameworks that ship their own PSR-17 but where you forgot to hand the factories in.","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"],"exampleFix":"// before\n$psr7 = $response->toPsrResponse(); // LogicException\n\n// after\nuse GuzzleHttp\\Psr7\\HttpFactory;\n$factory = new HttpFactory();\n$psr7 = $response->toPsrResponse($factory, $factory);","handlingStrategy":"validation","validationCode":"// Verify PSR-17 availability before bridging\nif ($responseFactory === null && ! class_exists(\\Nyholm\\Psr7\\Factory\\Psr17Factory::class) && ! class_exists(\\Http\\Discovery\\Psr17FactoryDiscovery::class)) {\n    throw new LogicException('Install nyholm/psr7 or pass PSR-17 factories to toPsrResponse()');\n}\n$psr7 = $response->toPsrResponse();","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["php","easywechat","psr-7","psr-17","dependencies"],"backgroundTag":"missing-psr17-factories","analyzedSha":"f0cf0a8b8361417ed683b8246d0ecbaf0aafcaa8","analyzedAt":"2026-08-21T05:29:19.565Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}