1: | <?php |
2: | namespace Worldline\Acquiring\Sdk\Authentication; |
3: | |
4: | |
5: | |
6: | |
7: | |
8: | |
9: | class DefaultOAuth2TokenCache implements OAuth2TokenCache |
10: | { |
11: | const OAUTH2_ACCESS_TOKEN_PREFIX = 'acquiring.api.oauth2.access-token'; |
12: | const EXPIRATION_TIMESTAMP_PREFIX = 'acquiring.api.oauth2.expiration-timestamp'; |
13: | |
14: | |
15: | private $array; |
16: | |
17: | |
18: | |
19: | |
20: | public function __construct(&$array = array()) |
21: | { |
22: | $this->array = &$array; |
23: | } |
24: | |
25: | |
26: | |
27: | |
28: | |
29: | public function getOAuth2AccessToken($tokenType) |
30: | { |
31: | $accessTokenKey = self::OAUTH2_ACCESS_TOKEN_PREFIX . $tokenType; |
32: | $timestampKey = self::EXPIRATION_TIMESTAMP_PREFIX . $tokenType; |
33: | if (isset($this->array[$accessTokenKey]) && isset($this->array[$timestampKey])) { |
34: | $expirationTimestamp = intval($this->array[$timestampKey]); |
35: | if ($expirationTimestamp > time()) { |
36: | return $this->array[$accessTokenKey]; |
37: | } |
38: | } |
39: | return null; |
40: | } |
41: | |
42: | |
43: | |
44: | |
45: | |
46: | |
47: | public function storeOAuth2AccessToken($tokenType, $oauth2AccessToken, $expirationTimestamp) |
48: | { |
49: | $this->array[self::OAUTH2_ACCESS_TOKEN_PREFIX . $tokenType] = $oauth2AccessToken; |
50: | $this->array[self::EXPIRATION_TIMESTAMP_PREFIX . $tokenType] = strval($expirationTimestamp); |
51: | } |
52: | |
53: | } |
54: | |