1
|
|
|
<?php
|
2
|
|
|
|
3
|
|
|
namespace PFlorek\AwsParameterStore;
|
4
|
|
|
|
5
|
|
|
|
6
|
|
|
class Options
|
7
|
|
|
{
|
8
|
|
|
const DEFAULT_PROFILE_SEPARATOR = '_';
|
9
|
|
|
const KEY_PREFIX = 'prefix';
|
10
|
|
|
const KEY_APPLICATION_NAME = 'name';
|
11
|
|
|
const KEY_DEFAULT_CONTEXT = 'sharedContext';
|
12
|
|
|
const KEY_PROFILE_SEPARATOR = 'profileSeparator';
|
13
|
|
|
|
14
|
|
|
/**
|
15
|
|
|
* @var string
|
16
|
|
|
*/
|
17
|
|
|
private $prefix;
|
18
|
|
|
|
19
|
|
|
/**
|
20
|
|
|
* @var string
|
21
|
|
|
*/
|
22
|
|
|
private $sharedContext;
|
23
|
|
|
|
24
|
|
|
/**
|
25
|
|
|
* @var string
|
26
|
|
|
*/
|
27
|
|
|
private $profileSeparator;
|
28
|
|
|
|
29
|
|
|
/**
|
30
|
|
|
* @var string
|
31
|
|
|
*/
|
32
|
|
|
private $applicationName;
|
33
|
|
|
|
34
|
|
|
/**
|
35
|
|
|
* @param string $prefix
|
36
|
|
|
* @param string $applicationName
|
37
|
|
|
* @param string $profileSeparator
|
38
|
|
|
* @param string $sharedContext
|
39
|
|
|
*/
|
40
|
|
|
public function __construct(string $prefix, string $applicationName, string $profileSeparator = self::DEFAULT_PROFILE_SEPARATOR, $sharedContext = '')
|
41
|
|
|
{
|
42
|
|
|
$this->prefix = $prefix;
|
43
|
|
|
$this->applicationName = $applicationName;
|
44
|
|
|
$this->sharedContext = $sharedContext;
|
45
|
|
|
$this->profileSeparator = $profileSeparator;
|
46
|
|
|
}
|
47
|
|
|
|
48
|
|
|
/**
|
49
|
|
|
* @param string[] $options
|
50
|
|
|
* @return Options
|
51
|
|
|
*/
|
52
|
|
|
public static function create(array $options): Options
|
53
|
|
|
{
|
54
|
|
|
$prefix = $options[self::KEY_PREFIX];
|
55
|
|
|
$name = $options[self::KEY_APPLICATION_NAME];
|
56
|
|
|
$sharedContext = $options['defaultContext'] ?? $options[self::KEY_DEFAULT_CONTEXT] ?? '';
|
57
|
|
|
$profileSeparator = $options[self::KEY_PROFILE_SEPARATOR] ?? self::DEFAULT_PROFILE_SEPARATOR;
|
58
|
|
|
|
59
|
|
|
return new Options($prefix, $name, $profileSeparator, $sharedContext);
|
60
|
|
|
}
|
61
|
|
|
|
62
|
|
|
/**
|
63
|
|
|
* @return string
|
64
|
|
|
*/
|
65
|
|
|
public function getPrefix(): string
|
66
|
|
|
{
|
67
|
|
|
return $this->prefix;
|
68
|
|
|
}
|
69
|
|
|
|
70
|
|
|
/**
|
71
|
|
|
* @return string
|
72
|
|
|
*/
|
73
|
|
|
public function getSharedContext(): string
|
74
|
|
|
{
|
75
|
|
|
return $this->sharedContext;
|
76
|
|
|
}
|
77
|
|
|
|
78
|
|
|
/**
|
79
|
|
|
* @return string
|
80
|
|
|
*/
|
81
|
|
|
public function getProfileSeparator(): string
|
82
|
|
|
{
|
83
|
|
|
return $this->profileSeparator;
|
84
|
|
|
}
|
85
|
|
|
|
86
|
|
|
/**
|
87
|
|
|
* @return string
|
88
|
|
|
*/
|
89
|
|
|
public function getApplicationName(): string
|
90
|
|
|
{
|
91
|
|
|
return $this->applicationName;
|
92
|
|
|
}
|
93
|
|
|
} |