Skip to content

Commit 4b8a137

Browse files
committed
added check to see if an api key is passed in instead of a config object
1 parent c2e4758 commit 4b8a137

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

lib/SparkPost/SparkPost.php

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,59 +2,65 @@
22
namespace SparkPost;
33

44
class SparkPost {
5-
5+
66
private static $config;
77
private static $defaults = array(
88
'host'=>'api.sparkpost.com',
99
'protocol'=>'https',
1010
'port'=>443,
1111
'strictSSL'=>true,
1212
'key'=>'',
13-
'version'=>'v1'
13+
'version'=>'v1'
1414
);
15-
15+
1616
/**
1717
* Enforce that this object can't be instansiated
1818
*/
1919
private function __construct(){}
20-
20+
2121
/**
2222
* Allows the user to pass in values to override the defaults and set their API key
23-
* @param Array $configMap - Hashmap that contains config values for the SDK to connect to SparkPost
23+
* @param String | Array $config - if a string it is an api key
24+
* If an array, is should contain config values for the SDK to connect to SparkPost
2425
* @throws \Exception
2526
*/
26-
public static function setConfig(array $configMap) {
27-
//check for API key because its required
28-
if (isset($configMap['key'])){
29-
$key = trim($configMap['key']);
27+
public static function setConfig($config) {
28+
// if the config map is a string we should assume that its an api key
29+
if (gettype($config) === 'string') {
30+
$config = ['key'=>$config];
31+
}
32+
33+
//check for API key because its required
34+
if (isset($config['key'])){
35+
$key = trim($config['key']);
3036
if(empty($key)){
3137
throw new \Exception('You must provide an API key');
3238
}
3339
} else {
3440
throw new \Exception('You must provide an API key');
3541
}
3642
self::$config = self::$defaults;
37-
foreach ($configMap as $configOption => $configValue) {
43+
foreach ($config as $configOption => $configValue) {
3844
if(key_exists($configOption, self::$config)) {
3945
self::$config[$configOption] = $configValue;
4046
}
4147
}
4248
}
43-
49+
4450
/**
4551
* Retrieves the configuration that was previously setup by the user
4652
* @throws \Exception
4753
*/
4854
public static function getConfig() {
49-
if (self::$config === null) {
55+
if (self::$config === null) {
5056
throw new \Exception('No configuration has been provided');
5157
}
5258
return self::$config;
5359
}
54-
60+
5561
public static function unsetConfig() {
5662
self::$config = NULL;
5763
}
5864
}
5965

60-
?>
66+
?>

0 commit comments

Comments
 (0)