setono / http-client-bundle
v0.2.0
2022-06-09 08:37 UTC
Requires
- php: >=7.4
- ext-json: *
- psr/log: ^1.1
- symfony/config: ^4.4 || ^5.4 || ^6.0
- symfony/dependency-injection: ^4.4 || ^5.4 || ^6.0
- symfony/http-client-contracts: ^2.3
- symfony/http-kernel: ^4.4 || ^5.4 || ^6.0
- symfony/service-contracts: ^2.2
Requires (Dev)
- phpunit/phpunit: ^9.5
- roave/security-advisories: dev-latest
- setono/code-quality-pack: ^2.2
- symfony/http-client: ^4.4 || ^5.4 || ^6.0
This package is auto-updated.
Last update: 2022-09-16 08:28:15 UTC
README
请使用 https://github.com/Setono/request-aware-http-client 代替
此包将装饰Symfonys HTTP客户端,使其能够检索完整的请求以进行调试等。
安装
步骤 1: 下载
$ composer require setono/http-client-bundle
步骤 2: 启用包
如果您使用 Symfony Flex,它将自动启用。否则,您需要将其添加到 config/bundles.php
。
<?php // config/bundles.php return [ // ... Setono\HttpClientBundle\SetonoHttpClientBundle::class => ['all' => true], // ... ];
用法
目前您需要手动装饰您的HTTP客户端。将来这将为您自动完成。
<?php use Setono\HttpClientBundle\HttpClient\RequestAwareHttpClient; use Setono\HttpClientBundle\HttpClient\RequestAwareHttpClientInterface; use Symfony\Contracts\HttpClient\HttpClientInterface; class YourService { private RequestAwareHttpClientInterface $httpClient; public function __construct(HttpClientInterface $httpClient) { $this->httpClient = new RequestAwareHttpClient($httpClient); } public function doSomething(): void { $response = $this->httpClient->request('POST', 'https://httpbin.org/post', [ 'json' => ['name' => 'John Doe'] ]); $request = $this->httpClient->getRequestFromResponse($response); echo $request->asString(); // Outputs: // POST https://httpbin.org/post {"name":"John Doe"} } }