1: | <?php |
2: | namespace Worldline\Connect\Sdk\Webhooks; |
3: | |
4: | use UnexpectedValueException; |
5: | |
6: | |
7: | |
8: | |
9: | |
10: | |
11: | class InMemorySecretKeyStore implements SecretKeyStore |
12: | { |
13: | |
14: | private $secretKeys; |
15: | |
16: | |
17: | |
18: | |
19: | public function __construct($secretKeys = array()) |
20: | { |
21: | $this->secretKeys = $secretKeys; |
22: | } |
23: | |
24: | |
25: | |
26: | |
27: | |
28: | |
29: | public function getSecretKey($keyId) |
30: | { |
31: | if (!isset($this->secretKeys[$keyId]) || is_null($this->secretKeys[$keyId])) { |
32: | throw new SecretKeyNotAvailableException($keyId, "could not find secret key for key id $keyId"); |
33: | } |
34: | return $this->secretKeys[$keyId]; |
35: | } |
36: | |
37: | |
38: | |
39: | |
40: | |
41: | |
42: | public function storeSecretKey($keyId, $secretKey) |
43: | { |
44: | if (is_null($keyId) || strlen(trim($keyId)) == 0) { |
45: | throw new UnexpectedValueException("keyId is required"); |
46: | } |
47: | if (is_null($secretKey) || strlen(trim($secretKey)) == 0) { |
48: | throw new UnexpectedValueException("secretKey is required"); |
49: | } |
50: | $this->secretKeys[$keyId] = $secretKey; |
51: | } |
52: | |
53: | |
54: | |
55: | |
56: | |
57: | public function removeSecretKey($keyId) |
58: | { |
59: | unset($this->secretKeys[$keyId]); |
60: | } |
61: | |
62: | |
63: | |
64: | |
65: | public function clear() |
66: | { |
67: | unset($this->secretKeys); |
68: | $this->secretKeys = array(); |
69: | } |
70: | } |
71: | |