Fix copyright
[gitphp.git] / include / Config.class.php
blob:a/include/Config.class.php -> blob:b/include/Config.class.php
--- a/include/Config.class.php
+++ b/include/Config.class.php
@@ -1,72 +1,31 @@
 <?php
 /**
- * GitPHP
  * Configfile reader class
  *
  * @author Christopher Han <xiphux@gmail.com>
  * @copyright Copyright (c) 2010 Christopher Han
  * @package GitPHP
  */
-
-/**
- * Config class
- *
- * @package GitPHP
- */
-class Config
+class GitPHP_Config
 {
-	
 	/**
-	 * instance
-	 *
-	 * Stores the singleton instance
-	 *
-	 * @access protected
-	 * @static
-	 */
-	protected static $instance;
-
-	/**
-	 * values
-	 *
 	 * Stores the config values
 	 *
-	 * @access protected
+	 * @var array
 	 */
 	protected $values = array();
 
 	/**
-	 * configs
-	 *
-	 * Stores the config files
-	 *
-	 * @access protected
+	 * Class constructor
 	 */
-	protected $configs = array();
-
-	/**
-	 * GetInstance
-	 *
-	 * Returns the singleton instance
-	 *
-	 * @access public
-	 * @static
-	 * @return mixed instance of config class
-	 */
-	public static function GetInstance()
+	public function __construct()
 	{
-		if (!self::$instance) {
-			self::$instance = new Config();
-		}
-		return self::$instance;
+		$this->InitializeDefaults();
 	}
 
 	/**
-	 * LoadConfig
-	 *
 	 * Loads a config file
 	 *
-	 * @access public
 	 * @param string $configFile config file to load
 	 * @throws Exception on failure
 	 */
@@ -76,56 +35,45 @@
 		// making use of these variables in their title
 		global $gitphp_version, $gitphp_appstring;
 
-		if (!is_file($configFile)) {
-			throw new Exception('Invalid config file ' . $configFile);
+		if (!is_readable($configFile)) {
+			throw new GitPHP_InvalidConfigFileException($configFile);
 		}
 
 		if (!include($configFile)) {
-			throw new Exception('Could not read config file ' . $configFile);
+			throw new GitPHP_InvalidConfigFileException($configFile);
 		}
 
-		$this->values = array_merge($this->values, $gitphp_conf);
-
-		$this->configs[] = $configFile;
+		if (isset($gitphp_conf) && is_array($gitphp_conf))
+			$this->values = array_merge($this->values, $gitphp_conf);
 	}
 
 	/**
-	 * ClearConfig
-	 *
 	 * Clears all config values
-	 *
-	 * @access public
 	 */
 	public function ClearConfig()
 	{
 		$this->values = array();
-		$this->configs = array();
+		$this->InitializeDefaults();
 	}
 
 	/**
-	 * GetValue
-	 *
 	 * Gets a config value
 	 *
-	 * @access public
-	 * @param $key config key to fetch
-	 * @param $default default config value to return
+	 * @param string $key config key to fetch
 	 * @return mixed config value
 	 */
-	public function GetValue($key, $default = null)
+	public function GetValue($key)
 	{
 		if ($this->HasKey($key)) {
 			return $this->values[$key];
 		}
-		return $default;
+
+		return null;
 	}
 
 	/**
-	 * SetValue
-	 *
 	 * Sets a config value
 	 *
-	 * @access public
 	 * @param string $key config key to set
 	 * @param mixed $value value to set
 	 */
@@ -142,11 +90,8 @@
 	}
 
 	/**
-	 * HasKey
-	 *
 	 * Tests if the config has specified this key
 	 *
-	 * @access public
 	 * @param string $key config key to find
 	 * @return boolean true if key exists
 	 */
@@ -158,5 +103,32 @@
 		return isset($this->values[$key]);
 	}
 
+	/**
+	 * Initializes default config values
+	 */
+	private function InitializeDefaults()
+	{
+		$this->values['objectmemory'] = 0;
+		$this->values['objectcache'] = false;
+		$this->values['objectcachelifetime'] = 86400;
+		$this->values['cache'] = false;
+		$this->values['debug'] = false;
+		$this->values['benchmark'] = false;
+		$this->values['stylesheet'] = 'gitphpskin.css';
+		$this->values['javascript'] = true;
+		$this->values['googlejs'] = false;
+		$this->values['search'] = true;
+		$this->values['filesearch'] = true;
+		$this->values['cacheexpire'] = true;
+		$this->values['largeskip'] = 200;
+		$this->values['filemimetype'] = true;
+		$this->values['geshi'] = true;
+		$this->values['exportedonly'] = false;
+		$this->values['compressformat'] = GITPHP_COMPRESS_ZIP;
+		$this->values['locale'] = 'en_US';
+		$this->values['graphs'] = false;
+		$this->values['objectcachecompress'] = 500;
+	}
+
 }
 

comments