-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathManager.php
78 lines (62 loc) · 2.06 KB
/
Manager.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
declare(strict_types=1);
/*
* @author Aaron Scherer <[email protected]>
* @date 2019
* @license https://opensource.org/licenses/MIT
*/
namespace Secretary;
use Secretary\Adapter\AdapterInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
/**
* Class Manager.
*
* @package Secretary
*/
class Manager
{
private AdapterInterface $adapter;
public function __construct(AdapterInterface $adapter)
{
$this->adapter = $adapter;
}
/**
* @throws Exception\SecretNotFoundException
*/
public function getSecret(string $key, ?array $options = []): Secret
{
$resolver = new OptionsResolver();
$this->adapter->configureSharedOptions($resolver);
$this->adapter->configureGetSecretOptions($resolver);
return $this->adapter->getSecret($key, $resolver->resolve($options));
}
public function putSecret(Secret $secret, ?array $options = []): Secret
{
$resolver = new OptionsResolver();
$this->adapter->configureSharedOptions($resolver);
$this->adapter->configurePutSecretOptions($resolver);
return $this->adapter->putSecret($secret, $resolver->resolve($options));
}
/**
* @throws Exception\SecretNotFoundException
*/
public function deleteSecretByKey(string $key, ?array $options = []): void
{
$secret = $this->getSecret($key, $options);
$resolver = new OptionsResolver();
$this->adapter->configureSharedOptions($resolver);
$this->adapter->configureDeleteSecretOptions($resolver);
$this->adapter->deleteSecret($secret, $resolver->resolve($options));
}
public function deleteSecret(Secret $secret, ?array $options = []): void
{
$resolver = new OptionsResolver();
$this->adapter->configureSharedOptions($resolver);
$this->adapter->configureDeleteSecretOptions($resolver);
$this->adapter->deleteSecret($secret, $resolver->resolve($options));
}
public function getAdapter(): AdapterInterface
{
return $this->adapter;
}
}