blob: 106d1d56efdc1733c576d0dad5e10f88584e5a3b (
plain)
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
|
<?php
namespace MessageSystems;
class Configuration {
private static $config;
private static $defaults = [
'host'=>'app.cloudplaceholder.com',
'protocol'=>'https',
'port'=>443,
'strictSSL'=>true,
'key'=>'',
'version'=>'v1'
];
/**
* Enforce that this object can't be instansiated
*/
private function __construct(){}
/**
* Allows the user to pass in values to override the defaults and set their API key
* @param Array $configMap - Hashmap that contains config values for the SDK to connect to SparkPost
* @throws \Exception
*/
public static function setConfig($configMap) {
//check for API key because its required
if (!isset($configMap['key']) || empty(trim($configMap['key']))){
throw new \Exception('You must provide an API key');
}
self::$config = self::$defaults;
foreach ($configMap as $configOption => $configValue) {
if(key_exists($configOption, self::$config)) {
self::$config[$configOption] = $configValue;
}
}
}
/**
* Retrieves the configuration that was previously setup by the user
* @throws \Exception
*/
public static function getConfig() {
if (self::$config === null) {
throw new \Exception('No configuration has been provided');
}
return self::$config;
}
}
?>
|