Skip to content

Commit

Permalink
Allow a custom client to be passed. (#5)
Browse files Browse the repository at this point in the history
* Replace php cs fixer with a shim version.

* Allow a custom client to be passed.
  • Loading branch information
l-you committed Mar 8, 2024
1 parent dac87bb commit 4718074
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"require-dev": {
"jane-php/open-api-3": "^7.6",
"phpstan/phpstan": "^1.10",
"friendsofphp/php-cs-fixer": "*"
"php-cs-fixer/shim": "^3.51"

},
"authors": [
{
Expand Down
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 4718074

Please sign in to comment.