BxDolConfig.php 2.8 KB

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