BxDolConfig.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. $this->aPathDynamic = array();
  57. $this->aDb = array(
  58. 'visual_processing' => true,
  59. 'debug_mode' => true,
  60. 'error_remort_by_email' => false
  61. );
  62. }
  63. function get($sGroup, $sName)
  64. {
  65. return $this->{$this->getVarName($sGroup)}[$sName];
  66. }
  67. function getGroup($sGroup)
  68. {
  69. return $this->{$this->getVarName($sGroup)};
  70. }
  71. function set($sGroup, $sName, $sValue, $bDefine = false)
  72. {
  73. if($bDefine)
  74. define($this->getDefineName($sGroup, $sName), $sValue);
  75. else
  76. $this->{$this->getVarName($sGroup)}[$sName] = $sValue;
  77. }
  78. function setGroup($sGroup, $aValue, $bDefine = false)
  79. {
  80. if($bDefine)
  81. foreach($aValue as $sName => $sValue)
  82. define($this->getDefineName($sGroup, $sName), $sValue);
  83. else {
  84. $sGroup = $this->getVarName($sGroup);
  85. if(!empty($this->$sGroup) && is_array($this->$sGroup))
  86. $this->$sGroup = array_merge($this->$sGroup, $aValue);
  87. else
  88. $this->$sGroup = $aValue;
  89. }
  90. }
  91. private function getVarName($sVar)
  92. {
  93. return 'a' . bx_gen_method_name($sVar);
  94. }
  95. private function getDefineName()
  96. {
  97. $aArgs = func_get_args();
  98. return 'BX_' . strtoupper(implode('_', $aArgs));
  99. }
  100. }
  101. /** @} */