class_mcConfig.inc.php 1.94 KB
<?php
/** 
 * @copyright (c) 2014, netz.coop eG
 */

class mcConfig {
	private static $configs = array (
		'tmpdir'		=>		'/tmp/',
		'charset'			=> 'utf-8',
		'storable_data'		=> array(
			'kindof'	=>	'MySql',
			'user'		=> 'user',
			'db'		=> 'database',
			'passwd'	=> 'password',
			'host'		=> 'localhost',
		),
	);
	
	public static function setConfig(array $param_Configs) {
		if(is_array($param_Configs) && !empty($param_Configs)) {
			self::$configs = $param_Configs;
			return true;
		} else {
			return false;
		}
	}
	
	public static function getConfig($param_column, $param_param=null) {
		if(array_key_exists($param_column, self::$configs)) {
			
			if(is_null($param_param)) {
				return self::$configs[$param_column];
				
			} else if(array_key_exists($param_param, self::$configs[$param_column])) {
				return self::$configs[$param_column][$param_param];
				
			} else {
				return false;
			}

		} else {
			return false;
		}
	}


	public static function getDSN() {
		if(array_key_exists('storable_data', self::$configs) && is_array(self::$configs['storable_data'])
				&& array_key_exists('kindof', self::$configs['storable_data']) && self::$configs['storable_data']['kindof']
				&& array_key_exists('user', self::$configs['storable_data']) && self::$configs['storable_data']['user']
				&& array_key_exists('db', self::$configs['storable_data']) && self::$configs['storable_data']['db']
				&& array_key_exists('passwd', self::$configs['storable_data']) && self::$configs['storable_data']['passwd']
				&& array_key_exists('host', self::$configs['storable_data']) && self::$configs['storable_data']['host']
				) {
			
			$dsn=  strtolower(self::$configs['storable_data']['kindof'])
						.'://'.self::$configs['storable_data']['user']
						.':'.self::$configs['storable_data']['passwd']
						.'@'.self::$configs['storable_data']['host']
						.'/'.self::$configs['storable_data']['db']; 
			
			D::li($dsn);
			return $dsn;
		} else {
			return false;
		}
		
	}
}

?>