ConfigHelper.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. require_once dirname(dirname(__FILE__)).'/model/SDKException.php';;
  3. /**
  4. * 配置文件辅助类
  5. */
  6. class ConfigHelper{
  7. private static $config = array();
  8. public static function getIntVal($key){
  9. if(is_array(self::$config) && self::$config == null){
  10. self::$config = include dirname(dirname(__FILE__)).'/config/config.inc.php';
  11. }
  12. if(is_array(self::$config) && self::$config != null){
  13. if(array_key_exists($key, self::$config)){
  14. return intval(self::$config[$key]);
  15. }
  16. }
  17. else{
  18. throw new SDKException('配置文件解析错误,请检查/config/config.inc.php');
  19. }
  20. }
  21. public static function getStrVal($key){
  22. if(is_array(self::$config) && self::$config == null){
  23. self::$config = include dirname(dirname(__FILE__)).'/config/config.inc.php';
  24. }
  25. if(is_array(self::$config) && self::$config != null){
  26. if(array_key_exists($key, self::$config)){
  27. return self::$config[$key];
  28. }
  29. }
  30. else{
  31. throw new SDKException('配置文件解析错误,请检查/config/config.inc.php');
  32. }
  33. }
  34. public static function getIntValWithDefault($key, $default){
  35. if(is_array(self::$config) && self::$config == null){
  36. self::$config = include dirname(dirname(__FILE__)).'/config/config.inc.php';
  37. }
  38. if(is_array(self::$config) && self::$config != null){
  39. if(array_key_exists($key, self::$config)){
  40. return intval(self::$config[$key]);
  41. }
  42. return $default;
  43. }
  44. else{
  45. throw new SDKException('配置文件解析错误,请检查/config/config.inc.php');
  46. }
  47. }
  48. public static function getStrValWithDefault($key, $default){
  49. if(is_array(self::$config) && self::$config == null){
  50. self::$config = include dirname(dirname(__FILE__)).'/config/config.inc.php';
  51. }
  52. if(is_array(self::$config) && self::$config != null){
  53. if(array_key_exists($key, self::$config)){
  54. return self::$config[$key];
  55. }
  56. else{
  57. return $default;
  58. }
  59. }
  60. else{
  61. throw new SDKException('配置文件解析错误,请检查/config/config.inc.php');
  62. }
  63. }
  64. }