summaryrefslogtreecommitdiffstats
path: root/lib/MessageSystems/Configuration.php
blob: 9f7c4ea6fc14e3a15d0c64c9546acb0c590f801f (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
<?php
namespace MessageSystems;

class Configuration {
	
	private static $config;
	private static $defaults = [
			'host'=>'app.cloudplaceholder.com',
			'protocol'=>'https',
			'port'=>443,
			'strictSSL'=>true,
			'key'=>'',
			'version'=>'v1'	
		];
	
	
	private function __constructor(){
	}
	
	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) {
			self::$config[$configOption] = $configValue;
		}
	}
	
	public static function getConfig() {
		if (self::$config === null) {	
			throw new \Exception('No configuration has been provided');
		}
		return self::$config;
	}
}

?>