BxDolConfig.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. var $aUrlStatic;
  15. var $aUrlDynamic;
  16. var $aPathStatic;
  17. var $aPathDynamic;
  18. var $aDb;
  19. /**
  20. * constructor
  21. */
  22. function BxDolConfig() {
  23. if(isset($GLOBALS['bxDolClasses'][get_class($this)]))
  24. trigger_error('Multiple instances are not allowed for the class: ' . get_class($this), E_USER_ERROR);
  25. parent::BxDol();
  26. $this->aUrlStatic = array();
  27. $this->aUrlDynamic = array();
  28. $this->aPathStatic = array();
  29. $this->aPathDynamic = array();
  30. $this->aDb = array();
  31. }
  32. /**
  33. * Prevent cloning the instance
  34. */
  35. public function __clone() {
  36. if (isset($GLOBALS['bxDolClasses'][get_class($this)]))
  37. trigger_error('Clone is not allowed for the class: ' . get_class($this), E_USER_ERROR);
  38. }
  39. /**
  40. * Get singleton instance of the class
  41. */
  42. public static function getInstance() {
  43. if(!isset($GLOBALS['bxDolClasses'][__CLASS__])) {
  44. $GLOBALS['bxDolClasses'][__CLASS__] = new BxDolConfig();
  45. $GLOBALS['bxDolClasses'][__CLASS__]->init();
  46. }
  47. return $GLOBALS['bxDolClasses'][__CLASS__];
  48. }
  49. function init() {
  50. $this->aUrlDynamic = array(
  51. 'tmp' => BX_DOL_URL_ROOT . 'tmp/',
  52. 'rpr_images_main' => '', //--- For Site's main images like logo, etc
  53. 'rpr_images_promo' => '', //--- For Promo images
  54. 'rpr_images_watermark' => '' //--- For Watermarks
  55. );
  56. $this->aPathDynamic = array(
  57. 'tmp' => BX_DIRECTORY_PATH_ROOT . 'tmp/',
  58. 'rpr_images_main' => '', //--- For Site's main images like logo, etc
  59. 'rpr_images_promo' => '', //--- For Promo images
  60. 'rpr_images_watermark' => '' //--- For Watermarks
  61. );
  62. $this->aDb = array(
  63. 'visual_processing' => true,
  64. 'debug_mode' => true,
  65. 'error_remort_by_email' => false
  66. );
  67. }
  68. function get($sGroup, $sName) {
  69. return $this->{$this->getVarName($sGroup)}[$sName];
  70. }
  71. function getGroup($sGroup) {
  72. return $this->{$this->getVarName($sGroup)};
  73. }
  74. function set($sGroup, $sName, $sValue, $bDefine = false) {
  75. if($bDefine)
  76. define($this->getDefineName($sGroup, $sName), $sValue);
  77. else
  78. $this->{$this->getVarName($sGroup)}[$sName] = $sValue;
  79. }
  80. function setGroup($sGroup, $aValue, $bDefine = false) {
  81. if($bDefine)
  82. foreach($aValue as $sName => $sValue)
  83. define($this->getDefineName($sGroup, $sName), $sValue);
  84. else {
  85. $sGroup = $this->getVarName($sGroup);
  86. if(!empty($this->$sGroup) && is_array($this->$sGroup))
  87. $this->$sGroup = array_merge($this->$sGroup, $aValue);
  88. else
  89. $this->$sGroup = $aValue;
  90. }
  91. }
  92. private function getVarName($sVar) {
  93. return 'a' . bx_gen_method_name($sVar);
  94. }
  95. private function getDefineName() {
  96. $aArgs = func_get_args();
  97. return 'BX_' . strtoupper(implode('_', $aArgs));
  98. }
  99. }
  100. /** @} */