This commit is contained in:
2024-03-11 00:18:45 -04:00
parent 40ffe86ff7
commit 23bcb3435f

View File

@@ -28,9 +28,9 @@ class ApiTransport implements TransportInterface
private string $_clientSecret = '';
/**
* @var string
* @var string | null
*/
private string $_accessToken = '';
private ?string $_accessToken = '';
/**
* @var Guzzle
@@ -153,22 +153,23 @@ class ApiTransport implements TransportInterface
}
private function setToken()
private function setToken(): void
{
if ($this->_cache !== null) {
$this->_accessToken = $this->_cache->get('access_token');
$token = $this->_cache->get('access_token');
if ($token) {
$this->_accessToken = $token;
return;
}
} else {
if ($this->_logger !== null) {
$this->_logger->notice('No cache available for client. Providing a cache interface can improve client response times.');
}
$this->_logger?->notice('No cache available for client. Providing a cache interface can improve client response times.');
}
if (empty($this->_accessToken)) {
$this->refreshToken();
}
}
private function refreshToken(): void
{
$params = [
@@ -185,9 +186,9 @@ class ApiTransport implements TransportInterface
$body = $result->getBody()->getContents();
$data = json_decode($body, true, 512, JSON_THROW_ON_ERROR);
$this->_accessToken = $data->access_token;
$this->_accessToken = $data['access_token'];
$this->_cache?->set('access_token', $this->_accessToken, $data->expires_in);
$this->_cache?->set('access_token', $this->_accessToken, $data['expires_in']);
} catch (\JsonException | ServerException | RequestException | GuzzleException $exception) {