commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
Loading...
Searching...
No Matches
src
Client
TokenStorageProvider.php
1
<?php
2
3
declare(strict_types=1);
4
5
namespace
Commercetools\Client
;
6
7
class
TokenStorageProvider
implements
TokenProvider
8
{
12
private
$tokenStorage;
13
17
private
$anonymousProvider;
18
22
public
function
__construct
(
TokenStorage
$tokenStorage,
AnonymousFlowTokenProvider
$anonymousProvider)
23
{
24
$this->tokenStorage = $tokenStorage;
25
$this->anonymousProvider = $anonymousProvider;
26
}
27
31
public
function
refreshToken
():
Token
32
{
33
$token = $this->anonymousProvider->refreshToken();
34
$this->storeToken($token);
35
36
return
$token;
37
}
38
42
public
function
getToken
():
Token
43
{
44
$token = $this->tokenStorage->getAccessToken();
45
if
(!is_null($token)) {
46
return
new
TokenModel
($token);
47
}
48
49
if
($this->tokenStorage->getRefreshToken()) {
50
return
$this->
refreshToken
();
51
}
52
53
$token = $this->anonymousProvider->getToken();
54
$this->storeToken($token);
55
56
return
$token;
57
}
58
59
private
function
storeToken(
Token
$token): void
60
{
61
$this->tokenStorage->setAccessToken($token->
getValue
());
62
if
($token instanceof
RefreshableTokenModel
) {
63
$this->tokenStorage->setRefreshToken($token->getRefreshToken());
64
}
65
}
66
}
Commercetools\Client\AnonymousFlowTokenProvider
Definition
AnonymousFlowTokenProvider.php:10
Commercetools\Client\RefreshableTokenModel
Definition
RefreshableTokenModel.php:11
Commercetools\Client\TokenModel
Definition
TokenModel.php:16
Commercetools\Client\TokenStorageProvider
Definition
TokenStorageProvider.php:8
Commercetools\Client\TokenStorageProvider\__construct
__construct(TokenStorage $tokenStorage, AnonymousFlowTokenProvider $anonymousProvider)
Definition
TokenStorageProvider.php:22
Commercetools\Client\TokenStorageProvider\refreshToken
refreshToken()
Definition
TokenStorageProvider.php:31
Commercetools\Client\TokenStorageProvider\getToken
getToken()
Definition
TokenStorageProvider.php:42
Commercetools\Client\Token
Definition
Token.php:16
Commercetools\Client\Token\getValue
getValue()
Commercetools\Client\TokenProvider
Definition
TokenProvider.php:13
Commercetools\Client\TokenStorage
Definition
TokenStorage.php:8
Commercetools\Client
Definition
AnonymousFlowTokenProvider.php:5
Generated by
1.9.8