Config.class.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. /**
  3. * Configfile reader class
  4. *
  5. * @author Christopher Han <xiphux@gmail.com>
  6. * @copyright Copyright (c) 2010 Christopher Han
  7. * @package GitPHP
  8. */
  9. class GitPHP_Config
  10. {
  11. /**
  12. * Stores the config values
  13. *
  14. * @var array
  15. */
  16. protected $values = array();
  17. /**
  18. * Class constructor
  19. */
  20. public function __construct()
  21. {
  22. $this->InitializeDefaults();
  23. }
  24. /**
  25. * Loads a config file
  26. *
  27. * @param string $configFile config file to load
  28. * @throws Exception on failure
  29. */
  30. public function LoadConfig($configFile)
  31. {
  32. // backwards compatibility for people who have been
  33. // making use of these variables in their title
  34. global $gitphp_version, $gitphp_appstring;
  35. if (!is_readable($configFile)) {
  36. throw new GitPHP_InvalidConfigFileException($configFile);
  37. }
  38. if (!include($configFile)) {
  39. throw new GitPHP_InvalidConfigFileException($configFile);
  40. }
  41. if (isset($gitphp_conf) && is_array($gitphp_conf))
  42. $this->values = array_merge($this->values, $gitphp_conf);
  43. }
  44. /**
  45. * Clears all config values
  46. */
  47. public function ClearConfig()
  48. {
  49. $this->values = array();
  50. $this->InitializeDefaults();
  51. }
  52. /**
  53. * Gets a config value
  54. *
  55. * @param string $key config key to fetch
  56. * @return mixed config value
  57. */
  58. public function GetValue($key)
  59. {
  60. if ($this->HasKey($key)) {
  61. return $this->values[$key];
  62. }
  63. return null;
  64. }
  65. /**
  66. * Sets a config value
  67. *
  68. * @param string $key config key to set
  69. * @param mixed $value value to set
  70. */
  71. public function SetValue($key, $value)
  72. {
  73. if (empty($key)) {
  74. return;
  75. }
  76. if (empty($value)) {
  77. unset($this->values[$key]);
  78. return;
  79. }
  80. $this->values[$key] = $value;
  81. }
  82. /**
  83. * Tests if the config has specified this key
  84. *
  85. * @param string $key config key to find
  86. * @return boolean true if key exists
  87. */
  88. public function HasKey($key)
  89. {
  90. if (empty($key)) {
  91. return false;
  92. }
  93. return isset($this->values[$key]);
  94. }
  95. /**
  96. * Initializes default config values
  97. */
  98. private function InitializeDefaults()
  99. {
  100. $this->values['objectmemory'] = 0;
  101. $this->values['objectcache'] = false;
  102. $this->values['objectcachelifetime'] = 86400;
  103. $this->values['cache'] = false;
  104. $this->values['debug'] = false;
  105. $this->values['benchmark'] = false;
  106. $this->values['stylesheet'] = 'gitphpskin.css';
  107. $this->values['javascript'] = true;
  108. $this->values['googlejs'] = false;
  109. $this->values['search'] = true;
  110. $this->values['filesearch'] = true;
  111. $this->values['cacheexpire'] = true;
  112. $this->values['largeskip'] = 200;
  113. $this->values['filemimetype'] = true;
  114. $this->values['geshi'] = true;
  115. $this->values['exportedonly'] = false;
  116. $this->values['compressformat'] = GITPHP_COMPRESS_ZIP;
  117. $this->values['locale'] = 'en_US';
  118. $this->values['graphs'] = false;
  119. $this->values['objectcachecompress'] = 500;
  120. }
  121. }