diff options
author | nornholdj <nornholdj@gmail.com> | 2014-11-10 14:40:51 -0500 |
---|---|---|
committer | nornholdj <nornholdj@gmail.com> | 2014-11-10 14:40:51 -0500 |
commit | 638798a8fa0447d8ed0911752a7d0ba907b921e3 (patch) | |
tree | f83c83ac55f099673efecdb511a7d0edd99793f7 /lib/SparkPost/SparkPost.php | |
parent | fea870e7ce1a59accdb4e2e4be2c41170523d4c7 (diff) | |
download | php-sparkpost-638798a8fa0447d8ed0911752a7d0ba907b921e3.zip php-sparkpost-638798a8fa0447d8ed0911752a7d0ba907b921e3.tar.gz php-sparkpost-638798a8fa0447d8ed0911752a7d0ba907b921e3.tar.bz2 |
Updated SparkPost References and updated docs and mappings to reflect
updated config lists.
Diffstat (limited to 'lib/SparkPost/SparkPost.php')
-rw-r--r-- | lib/SparkPost/SparkPost.php | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/lib/SparkPost/SparkPost.php b/lib/SparkPost/SparkPost.php new file mode 100644 index 0000000..14af3cd --- /dev/null +++ b/lib/SparkPost/SparkPost.php @@ -0,0 +1,51 @@ +<?php +namespace SparkPost; + +class SparkPost { + + private static $config; + private static $defaults = [ + 'host'=>'api.sparkpost.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(array $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; + } +} + +?>
\ No newline at end of file |