diff options
author | beardyman <nornholdj@gmail.com> | 2015-10-04 19:42:14 -0400 |
---|---|---|
committer | beardyman <nornholdj@gmail.com> | 2015-10-04 19:42:14 -0400 |
commit | 4b8a1370698581fece4d5ec188851031e41dcad0 (patch) | |
tree | 5f449b6c275138bfaa13164daca31c90afd0f900 | |
parent | c2e4758d8df8cf7e20451ea3196f2dc918e245e1 (diff) | |
download | php-sparkpost-4b8a1370698581fece4d5ec188851031e41dcad0.zip php-sparkpost-4b8a1370698581fece4d5ec188851031e41dcad0.tar.gz php-sparkpost-4b8a1370698581fece4d5ec188851031e41dcad0.tar.bz2 |
added check to see if an api key is passed in instead of a config object
-rw-r--r-- | lib/SparkPost/SparkPost.php | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/lib/SparkPost/SparkPost.php b/lib/SparkPost/SparkPost.php index 755df46..a9035f9 100644 --- a/lib/SparkPost/SparkPost.php +++ b/lib/SparkPost/SparkPost.php @@ -2,7 +2,7 @@ namespace SparkPost; class SparkPost { - + private static $config; private static $defaults = array( 'host'=>'api.sparkpost.com', @@ -10,23 +10,29 @@ class SparkPost { 'port'=>443, 'strictSSL'=>true, 'key'=>'', - 'version'=>'v1' + '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 + * @param String | Array $config - if a string it is an api key + * If an array, is should contain config values for the SDK to connect to SparkPost * @throws \Exception */ - public static function setConfig(array $configMap) { - //check for API key because its required - if (isset($configMap['key'])){ - $key = trim($configMap['key']); + public static function setConfig($config) { + // if the config map is a string we should assume that its an api key + if (gettype($config) === 'string') { + $config = ['key'=>$config]; + } + + //check for API key because its required + if (isset($config['key'])){ + $key = trim($config['key']); if(empty($key)){ throw new \Exception('You must provide an API key'); } @@ -34,27 +40,27 @@ class SparkPost { throw new \Exception('You must provide an API key'); } self::$config = self::$defaults; - foreach ($configMap as $configOption => $configValue) { + foreach ($config 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) { + if (self::$config === null) { throw new \Exception('No configuration has been provided'); } return self::$config; } - + public static function unsetConfig() { self::$config = NULL; } } -?>
\ No newline at end of file +?> |