BxDolConfig.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup DolphinCore Dolphin Core
  7. * @{
  8. */
  9. bx_import('BxDol');
  10. /**
  11. * System class for main configuration settings.
  12. */
  13. class BxDolConfig extends BxDol implements iBxDolSingleton
  14. {
  15. protected $aUrlStatic;
  16. protected $aUrlDynamic;
  17. protected $aPathStatic;
  18. protected $aPathDynamic;
  19. protected $aDb;
  20. /**
  21. * constructor
  22. */
  23. protected function __construct()
  24. {
  25. if(isset($GLOBALS['bxDolClasses'][get_class($this)]))
  26. trigger_error('Multiple instances are not allowed for the class: ' . get_class($this), E_USER_ERROR);
  27. parent::__construct();
  28. $this->aUrlStatic = array();
  29. $this->aUrlDynamic = array();
  30. $this->aPathStatic = array();
  31. $this->aPathDynamic = array();
  32. $this->aDb = array();
  33. }
  34. /**
  35. * Prevent cloning the instance
  36. */
  37. public function __clone()
  38. {
  39. if (isset($GLOBALS['bxDolClasses'][get_class($this)]))
  40. trigger_error('Clone is not allowed for the class: ' . get_class($this), E_USER_ERROR);
  41. }
  42. /**
  43. * Get singleton instance of the class
  44. */
  45. public static function getInstance()
  46. {
  47. if(!isset($GLOBALS['bxDolClasses'][__CLASS__])) {
  48. $GLOBALS['bxDolClasses'][__CLASS__] = new BxDolConfig();
  49. $GLOBALS['bxDolClasses'][__CLASS__]->init();
  50. }
  51. return $GLOBALS['bxDolClasses'][__CLASS__];
  52. }
  53. function init()
  54. {
  55. $this->aUrlDynamic = array(
  56. 'tmp' => BX_DOL_URL_ROOT . 'tmp/',
  57. );
  58. $this->aPathDynamic = array(
  59. 'tmp' => BX_DIRECTORY_PATH_ROOT . 'tmp/',
  60. );
  61. $this->aDb = array(
  62. 'visual_processing' => true,
  63. 'debug_mode' => true,
  64. 'error_remort_by_email' => false
  65. );
  66. }
  67. function get($sGroup, $sName)
  68. {
  69. return $this->{$this->getVarName($sGroup)}[$sName];
  70. }
  71. function getGroup($sGroup)
  72. {
  73. return $this->{$this->getVarName($sGroup)};
  74. }
  75. function set($sGroup, $sName, $sValue, $bDefine = false)
  76. {
  77. if($bDefine)
  78. define($this->getDefineName($sGroup, $sName), $sValue);
  79. else
  80. $this->{$this->getVarName($sGroup)}[$sName] = $sValue;
  81. }
  82. function setGroup($sGroup, $aValue, $bDefine = false)
  83. {
  84. if($bDefine)
  85. foreach($aValue as $sName => $sValue)
  86. define($this->getDefineName($sGroup, $sName), $sValue);
  87. else {
  88. $sGroup = $this->getVarName($sGroup);
  89. if(!empty($this->$sGroup) && is_array($this->$sGroup))
  90. $this->$sGroup = array_merge($this->$sGroup, $aValue);
  91. else
  92. $this->$sGroup = $aValue;
  93. }
  94. }
  95. private function getVarName($sVar)
  96. {
  97. return 'a' . bx_gen_method_name($sVar);
  98. }
  99. private function getDefineName()
  100. {
  101. $aArgs = func_get_args();
  102. return 'BX_' . strtoupper(implode('_', $aArgs));
  103. }
  104. }
  105. /** @} */