1 | <?php |
||
2 | |||
3 | namespace NStack; |
||
4 | |||
5 | /** |
||
6 | * Class Config |
||
7 | * |
||
8 | * @package NStack |
||
9 | * @author Casper Rasmussen <[email protected]> |
||
10 | */ |
||
11 | class Config |
||
12 | { |
||
13 | /** @var string|null */ |
||
14 | protected $baseUrl = 'https://nstack.io'; |
||
15 | |||
16 | /** @var string */ |
||
17 | protected $version = 'v2'; |
||
18 | |||
19 | /** @var string */ |
||
20 | protected $appId; |
||
21 | |||
22 | /** @var string */ |
||
23 | protected $restApiKey; |
||
24 | |||
25 | /** @var string|null */ |
||
26 | protected $masterKey; |
||
27 | |||
28 | /** |
||
29 | * Config constructor. |
||
30 | * |
||
31 | * @param string $appId |
||
32 | * @param string $restApiKey |
||
33 | * @param string|null $masterKey |
||
34 | * @param string|null $baseUrl |
||
35 | * @param string $version |
||
36 | * @author Casper Rasmussen <[email protected]> |
||
37 | */ |
||
38 | 28 | public function __construct( |
|
39 | string $appId, |
||
40 | string $restApiKey, |
||
41 | ?string $masterKey = null, |
||
42 | ?string $baseUrl = null, |
||
43 | string $version = 'v2' |
||
44 | ) { |
||
45 | 28 | $this->appId = $appId; |
|
46 | 28 | $this->restApiKey = $restApiKey; |
|
47 | 28 | $this->masterKey = $masterKey; |
|
48 | |||
49 | 28 | if ($baseUrl) { |
|
50 | $this->baseUrl = $baseUrl; |
||
51 | } |
||
52 | |||
53 | 28 | $this->version = $version; |
|
54 | 28 | } |
|
55 | |||
56 | /** |
||
57 | * createFromArray |
||
58 | * |
||
59 | * @param array $data |
||
60 | * @return \NStack\Config |
||
61 | * @author Casper Rasmussen <[email protected]> |
||
62 | */ |
||
63 | public static function createFromArray(array $data): self |
||
64 | { |
||
65 | return new self( |
||
66 | $data['application_id'], |
||
67 | $data['rest_api_key'], |
||
68 | $data['master_key'] ?? null, |
||
69 | $data['base_url'] ?? null, |
||
70 | $data['version'] |
||
71 | ); |
||
72 | } |
||
73 | |||
74 | /** |
||
75 | * getBaseUrl |
||
76 | * |
||
77 | * @return string |
||
78 | * @author Casper Rasmussen <[email protected]> |
||
79 | */ |
||
80 | 1 | public function getBaseUrl(): string |
|
81 | { |
||
82 | 1 | return $this->baseUrl; |
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||
83 | } |
||
84 | |||
85 | /** |
||
86 | * setBaseUrl |
||
87 | * |
||
88 | * @param string $baseUrl |
||
89 | * @author Casper Rasmussen <[email protected]> |
||
90 | */ |
||
91 | public function setBaseUrl(string $baseUrl): void |
||
92 | { |
||
93 | $this->baseUrl = $baseUrl; |
||
94 | } |
||
95 | |||
96 | /** |
||
97 | * @return string |
||
98 | * @author Casper Rasmussen <[email protected]> |
||
99 | */ |
||
100 | 1 | public function getAppId(): string |
|
101 | { |
||
102 | 1 | return $this->appId; |
|
103 | } |
||
104 | |||
105 | /** |
||
106 | * setAppId |
||
107 | * |
||
108 | * @param string $appId |
||
109 | * @author Casper Rasmussen <[email protected]> |
||
110 | */ |
||
111 | public function setAppId(string $appId): void |
||
112 | { |
||
113 | $this->appId = $appId; |
||
114 | } |
||
115 | |||
116 | /** |
||
117 | * getRestApiKey |
||
118 | * |
||
119 | * @return string |
||
120 | * @author Casper Rasmussen <[email protected]> |
||
121 | */ |
||
122 | 1 | public function getRestApiKey(): string |
|
123 | { |
||
124 | 1 | return $this->restApiKey; |
|
125 | } |
||
126 | |||
127 | /** |
||
128 | * setRestApiKey |
||
129 | * |
||
130 | * @param string $restApiKey |
||
131 | * @author Casper Rasmussen <[email protected]> |
||
132 | */ |
||
133 | public function setRestApoKey(string $restApiKey): void |
||
134 | { |
||
135 | $this->restApiKey = $restApiKey; |
||
136 | } |
||
137 | |||
138 | /** |
||
139 | * getMasterKey |
||
140 | * |
||
141 | * @return string|null |
||
142 | * @author Casper Rasmussen <[email protected]> |
||
143 | */ |
||
144 | public function getMasterKey(): ?string |
||
145 | { |
||
146 | return $this->masterKey; |
||
147 | } |
||
148 | |||
149 | /** |
||
150 | * setMasterKey |
||
151 | * |
||
152 | * @param string|null $masterKey |
||
153 | * @author Casper Rasmussen <[email protected]> |
||
154 | */ |
||
155 | public function setMasterKey(?string $masterKey): void |
||
156 | { |
||
157 | $this->masterKey = $masterKey; |
||
158 | } |
||
159 | |||
160 | /** |
||
161 | * getVersion |
||
162 | * |
||
163 | * @return string |
||
164 | * @author Casper Rasmussen <[email protected]> |
||
165 | */ |
||
166 | 26 | public function getVersion(): string |
|
167 | { |
||
168 | 26 | return $this->version; |
|
169 | } |
||
170 | |||
171 | /** |
||
172 | * setVersion |
||
173 | * |
||
174 | * @param string $version |
||
175 | * @author Casper Rasmussen <[email protected]> |
||
176 | */ |
||
177 | public function setVersion(string $version): void |
||
178 | { |
||
179 | $this->version = $version; |
||
180 | } |
||
181 | } |
||
182 |