\GuzzleHttp\Client resolving hangs if contextual binding is done using make() or makeWith()

79 Views Asked by At

I am writing a simple API-wrapper and this wrapper needs the configured GuzzleHttp\Client instance as a dependency.

use GuzzleHttp\Client;

class Api {
    private $client;

    public function __construct(Client $client)
    {
        $this->client = $client;
    }
}

Everything works fine if I create Client instance using new Client() in AppServiceProvider->register():

$this->app->when(Api::class)
    ->needs(Client::class)
    ->give(function () {
        return new Client(['base_uri' => config('services.api.base_uri')]);
    });

But Api instance resolving hangs if I create Client instance using make() or makeWith():

$this->app->when(Api::class)
    ->needs(Client::class)
    ->give(function () {
        return $this->app->makeWith(Client::class, ['config' => ['base_uri' => config('services.api.base_uri')]]);
    });

I did fast testing via tinker:

app(\App\Api::class);

and it just hangs forever.

0

There are 0 best solutions below