BxDolConfig.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. /**
  3. * @package Dolphin Core
  4. * @copyright Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  5. * @license CC-BY - http://creativecommons.org/licenses/by/3.0/
  6. */
  7. defined('BX_DOL') or die('hack attempt');
  8. bx_import('BxDol');
  9. /**
  10. * System class for main configuration settings.
  11. */
  12. class BxDolConfig extends BxDol {
  13. var $aUrlStatic;
  14. var $aUrlDynamic;
  15. var $aPathStatic;
  16. var $aPathDynamic;
  17. var $aDb;
  18. /**
  19. * constructor
  20. */
  21. function BxDolConfig() {
  22. if(isset($GLOBALS['bxDolClasses'][get_class($this)]))
  23. trigger_error('Multiple instances are not allowed for the class: ' . get_class($this), E_USER_ERROR);
  24. parent::BxDol();
  25. $this->aUrlStatic = array();
  26. $this->aUrlDynamic = array();
  27. $this->aPathStatic = array();
  28. $this->aPathDynamic = array();
  29. $this->aDb = array();
  30. }
  31. /**
  32. * Prevent cloning the instance
  33. */
  34. public function __clone() {
  35. if (isset($GLOBALS['bxDolClasses'][get_class($this)]))
  36. trigger_error('Clone is not allowed for the class: ' . get_class($this), E_USER_ERROR);
  37. }
  38. /**
  39. * Get singleton instance of the class
  40. */
  41. public static function getInstance() {
  42. if(!isset($GLOBALS['bxDolClasses'][__CLASS__])) {
  43. $GLOBALS['bxDolClasses'][__CLASS__] = new BxDolConfig();
  44. $GLOBALS['bxDolClasses'][__CLASS__]->init();
  45. }
  46. return $GLOBALS['bxDolClasses'][__CLASS__];
  47. }
  48. function init() {
  49. $this->aUrlDynamic = array(
  50. 'tmp' => BX_DOL_URL_ROOT . 'tmp/',
  51. 'rpr_images_main' => '', //--- For Site's main images like logo, etc
  52. 'rpr_images_promo' => '', //--- For Promo images
  53. 'rpr_images_watermark' => '' //--- For Watermarks
  54. );
  55. $this->aPathDynamic = array(
  56. 'tmp' => BX_DIRECTORY_PATH_ROOT . 'tmp/',
  57. 'rpr_images_main' => '', //--- For Site's main images like logo, etc
  58. 'rpr_images_promo' => '', //--- For Promo images
  59. 'rpr_images_watermark' => '' //--- For Watermarks
  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. return $this->{$this->getVarName($sGroup)}[$sName];
  69. }
  70. function getGroup($sGroup) {
  71. return $this->{$this->getVarName($sGroup)};
  72. }
  73. function set($sGroup, $sName, $sValue, $bDefine = false) {
  74. if($bDefine)
  75. define($this->getDefineName($sGroup, $sName), $sValue);
  76. else
  77. $this->{$this->getVarName($sGroup)}[$sName] = $sValue;
  78. }
  79. function setGroup($sGroup, $aValue, $bDefine = false) {
  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. return 'a' . str_replace(' ', '', ucwords(str_replace('_', ' ', $sVar)));
  93. }
  94. private function getDefineName() {
  95. $aArgs = func_get_args();
  96. return 'BX_' . strtoupper(implode('_', $aArgs));
  97. }
  98. }