Skip to content

Commit

Permalink
Allow a custom client to be passed.
Browse files Browse the repository at this point in the history
  • Loading branch information
l-you committed Mar 8, 2024
1 parent 9e569cc commit 152b422
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/ClientFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,22 @@
use GuzzleHttp\Psr7\Uri;
use Http\Client\Common\Plugin\AddHostPlugin;
use Http\Client\Common\PluginClient;
use Http\Client\HttpAsyncClient;
use Http\Discovery\Psr18ClientDiscovery;
use Jane\Component\OpenApiRuntime\Client\Plugin\AuthenticationRegistry;
use Psr\Http\Client\ClientInterface;

final readonly class ClientFactory
{
public static function createClient(string $token = null): Client
public static function createClient(string $token = null,
HttpAsyncClient|ClientInterface $client = null): Client
{
$plugins = [];
if (null !== $token) {
$plugins[] = new AuthenticationRegistry([new BearerAuthentication($token)]);
}
$plugins[] = new AddHostPlugin(new Uri('https://api.checkbox.in.ua'), ['replace' => true]);
$pluginClient = new PluginClient(Psr18ClientDiscovery::find(), $plugins);
$pluginClient = new PluginClient($client??Psr18ClientDiscovery::find(), $plugins);

return Client::create($pluginClient);
}
Expand Down

0 comments on commit 152b422

Please sign in to comment.