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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | <?php /** * Constant for tar archive */ define('GITPHP_COMPRESS_TAR', 'tar'); /** * Constant for bz2 archive */ define('GITPHP_COMPRESS_BZ2', 'tbz2'); /** * Constant for gz archive */ define('GITPHP_COMPRESS_GZ', 'tgz'); /** * Constant for zip archive */ define('GITPHP_COMPRESS_ZIP', 'zip'); /** * Configfile reader class * * @author Christopher Han <xiphux@gmail.com> * @copyright Copyright (c) 2010 Christopher Han * @package GitPHP */ class GitPHP_Config { /** * Stores the singleton instance * * @var GitPHP_Config */ protected static $instance; /** * Stores the config values * * @var array */ protected $values = array(); /** * Stores the config files * * @var string[] */ protected $configs = array(); /** * Returns the singleton instance * * @return GitPHP_Config instance of config class */ public static function GetInstance() { if (!self::$instance) { self::$instance = new GitPHP_Config(); } return self::$instance; } /** * Releases the singleton instance */ public static function DestroyInstance() { self::$instance = null; } /** * Class constructor */ private function __construct() { } /** * Loads a config file * * @param string $configFile config file to load * @throws Exception on failure */ public function LoadConfig($configFile) { // backwards compatibility for people who have been // making use of these variables in their title global $gitphp_version, $gitphp_appstring; if (!is_file($configFile)) { throw new GitPHP_MessageException('Could not load config file ' . $configFile, true, 500); } if (!include($configFile)) { throw new GitPHP_MessageException('Could not read config file ' . $configFile, true, 500); } if (isset($gitphp_conf) && is_array($gitphp_conf)) $this->values = array_merge($this->values, $gitphp_conf); $this->configs[] = $configFile; } /** * Clears all config values */ public function ClearConfig() { $this->values = array(); $this->configs = array(); } /** * Gets a config value * * @param string $key config key to fetch * @param mixed $default default config value to return * @return mixed config value */ public function GetValue($key, $default = null) { if ($this->HasKey($key)) { return $this->values[$key]; } return $default; } /** * Sets a config value * * @param string $key config key to set * @param mixed $value value to set */ public function SetValue($key, $value) { if (empty($key)) { return; } if (empty($value)) { unset($this->values[$key]); return; } $this->values[$key] = $value; } /** * Tests if the config has specified this key * * @param string $key config key to find * @return boolean true if key exists */ public function HasKey($key) { if (empty($key)) { return false; } return isset($this->values[$key]); } } |