0

I see in https://github.com/hannesvdvreken/guzzle-clockwork/blob/4.x/src/Support/Laravel/ServiceProvider.php

use $this->app->bind(ClinetInterface::class ... to create an guzzlehttp\client instance. but not working to me.

// provider/custom func register
$this->app->bind(Client::class, function () { throw new Exception(); })
// app.php
'prodiders' => [ app\provider\custom.php]
// app/console/commands/test.php
new GuzzleHttp\Client()

it's not work.

multi guzzlehttp use cases in my proj. i want dynamic replace the Client instance and inject a middleware direct return the fake response (mock data), how can i do this?

versions: laravel : 6.9.0 guzzlehttp/guzzle : 6.5.2

cevin
  • 43
  • 5
  • As I can see in GuzzleHttp library there is Middleware. There you can find functions, and maybe you can find what you need. So in your code add: 'use GuzzleHttp\Middleware;' – Tinxuanna Dec 06 '21 at 07:17
  • What is to say try something like that: $dynamicClient = new \GuzzleHttp\Middleware(); $response2 = $dynamicClient::mapResponse(); ... – Tinxuanna Dec 06 '21 at 07:23
  • @Tinxuanna The proj have multi developer and every people just direct use `new \GuzzleHttp\Client` to request thirdparty http api, now I want to record the logs of all guzzles used globally without modifying the code of others. – cevin Dec 06 '21 at 11:28
  • Maybe you can check the answers given in the link: [log api calls using guzzle](https://stackoverflow.com/questions/32681165/how-do-you-log-all-api-calls-using-guzzle-6). Give it a try, and when you are stuck again, feel free to ask. – Tinxuanna Dec 07 '21 at 06:39

0 Answers0