Skip to content

Commit

Permalink
WID-513 - Simplify UitpasAPIServiceProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
brampauwelyn committed Feb 28, 2024
1 parent d293d76 commit 5b29280
Showing 1 changed file with 29 additions and 34 deletions.
63 changes: 29 additions & 34 deletions app/UitpasAPI/UitpasAPIServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,34 @@

class UitpasAPIServiceProvider extends APIServiceProviderBase
{
public function register(Container $pimple)
{

$pimple['uitpas_api'] = function (Container $pimple) {

$guzzleClient = new Client(
[
'base_uri' => $pimple['uitpas_api.base_url'],
'headers' => [
'Content-type' => 'application/json; charset=utf-8',
'Accept' => 'application/ld+json',
'x-client-id' => $pimple['uitpas_api.x_client_id'],
],
'handler' => $this->getHandlerStack('uitpas_api', $pimple),
]
);

return new UitpasClient($guzzleClient);
};

$pimple['uitpas_api_test'] = function (Container $pimple) {

$uitpasClient = clone $pimple['uitpas_api'];

$config = $uitpasClient->getClient()->getConfig();
$config['base_uri'] = $pimple['uitpas_api_test.base_url'];
$headers = $config['headers'] ?? [];
$config['headers'] = $headers;
$config['headers']['x-client-id'] = $pimple['uitpas_api_test.x_client_id'];

$uitpasClient->setClient(new \GuzzleHttp\Client($config));

return $uitpasClient;
};
}
public function register(Container $pimple)
{
$pimple['uitpas_api'] = function (Container $pimple) {
return new UitpasClient(new Client($this->getConfig($pimple)));
};

$pimple['uitpas_api_test'] = function (Container $pimple) {
$config = $this->getConfig($pimple);
$config['base_uri'] = $pimple['uitpas_api_test.base_url'];
$config['headers']['x-client-id'] = $pimple['uitpas_api_test.x_client_id'];

return new UitpasClient(new Client($config));
};
}

private function getConfig(Container $pimple)
{
return [
'base_uri' => $pimple['uitpas_api.base_url'],
'headers' => [
'Content-type' => 'application/json; charset=utf-8',
'Accept' => 'application/ld+json',
'x-client-id' => $pimple['uitpas_api.x_client_id'],
],
'handler' => $this->getHandlerStack('uitpas_api', $pimple),
];
}


}

0 comments on commit 5b29280

Please sign in to comment.