Module: nagvis Branch: master Commit: a22eb94ad4a235291151a02b29bce69d0e11b366 URL: http://nagvis.git.sourceforge.net/git/gitweb.cgi?p=nagvis/nagvis;a=commit;h=a22eb94ad4a235291151a02b29bce69d0e11b366
Author: Lars Michelsen <[email protected]> Date: Thu Oct 22 19:24:32 2009 +0200 #11 some small improvements, comments --- share/frontend/nagvis-js/index.php | 2 +- share/server/core/classes/GlobalCore.php | 54 +++++++++++++++++++-------- share/server/core/classes/GlobalMainCfg.php | 2 +- 3 files changed, 40 insertions(+), 18 deletions(-) diff --git a/share/frontend/nagvis-js/index.php b/share/frontend/nagvis-js/index.php index 9038f80..e3df1e0 100644 --- a/share/frontend/nagvis-js/index.php +++ b/share/frontend/nagvis-js/index.php @@ -39,7 +39,7 @@ require('../../server/core/functions/oldPhpVersionFixes.php'); define('CONST_AJAX' , FALSE); // Initialize the core -$CORE = new GlobalCore(); +$CORE = GlobalCore::getInstance(); /* * Url: Parse the url to know later what module and diff --git a/share/server/core/classes/GlobalCore.php b/share/server/core/classes/GlobalCore.php index e01e3be..88c5eb9 100644 --- a/share/server/core/classes/GlobalCore.php +++ b/share/server/core/classes/GlobalCore.php @@ -28,32 +28,54 @@ * @author Lars Michelsen <[email protected] */ class GlobalCore { - public $MAINCFG; - public $LANG; + public $MAINCFG = null; + public $LANG = null; - private $iconsetTypeCache; + private static $instance = null; + private $iconsetTypeCache = Array(); /** - * Class Constructor + * Deny construct * * @author Lars Michelsen <[email protected]> */ - public function __construct($MAINCFG = NULL, $LANG = NULL) { - $this->iconsetTypeCache = Array(); - - if($MAINCFG == NULL) { - // Load the main configuration + private function __construct() {} + + /** + * Deny clone + * + * @author Lars Michelsen <[email protected]> + */ + private function __clone() {} + + /** + * Getter function to initialize MAINCFG and LANG when not done yet + * + * @author Lars Michelsen <[email protected]> + */ + public function __get($key) { + if($key == 'MAINCFG' && $this->MAINCFG === null) { + // Initialize main configuration when not set yet $this->MAINCFG = new GlobalMainCfg(CONST_MAINCFG); - } else { - $this->MAINCFG = $MAINCFG; + } elseif($key == 'LANG' && $this->LANG === null) { + // Initialize language when not set yet + $this->LANG = new GlobalLanguage($this->MAINCFG); } - if($LANG == NULL) { - // Initialize language - $this->LANG = new GlobalLanguage($this->MAINCFG); - } else { - $this->LANG = $LANG; + return $this->$key; + } + + /** + * Static method for getting the instance + * + * @author Lars Michelsen <[email protected]> + */ + public static function getInstance() { + if (self::$instance === null) { + self::$instance = new self; } + + return self::$instance; } /* Here are some methods defined which get used all over NagVis and have diff --git a/share/server/core/classes/GlobalMainCfg.php b/share/server/core/classes/GlobalMainCfg.php index 4fc7f57..b3d8052 100644 --- a/share/server/core/classes/GlobalMainCfg.php +++ b/share/server/core/classes/GlobalMainCfg.php @@ -1066,7 +1066,7 @@ class GlobalMainCfg { if(!preg_match($arrValidConfig[$key]['match'],$val)) { // wrong format if($printErr) { - $CORE = new GlobalCore($this); + $CORE = GlobalCore::getInstance(); new GlobalMessage('ERROR', $CORE->LANG->getText('wrongValueFormat', 'TYPE~'.$type.',ATTRIBUTE~'.$key), $CORE->MAINCFG->getValue('paths','htmlbase')); } return FALSE; ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ Nagvis-checkins mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/nagvis-checkins
