From: Roland Häder Date: Fri, 3 Oct 2008 00:34:11 +0000 (+0000) Subject: Configuration class is now fully singleton X-Git-Url: https://git.mxchange.org/?p=shipsimu.git;a=commitdiff_plain;h=84369c88ca8f57a1e4d9d20cdd4adf45576c5cd8 Configuration class is now fully singleton --- diff --git a/inc/classes/main/class_BaseFrameworkSystem.php b/inc/classes/main/class_BaseFrameworkSystem.php index fe43a99..38e689b 100644 --- a/inc/classes/main/class_BaseFrameworkSystem.php +++ b/inc/classes/main/class_BaseFrameworkSystem.php @@ -289,7 +289,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { Registry::isInitialized('OK'); } elseif ($this->__toString() == 'DebugMiddleware') { // Set configuration instance - $this->setConfigInstance(FrameworkConfiguration::createFrameworkConfiguration()); + $this->setConfigInstance(FrameworkConfiguration::getInstance()); } } diff --git a/inc/config.php b/inc/config.php index 65eba41..a9e58d7 100644 --- a/inc/config.php +++ b/inc/config.php @@ -30,7 +30,7 @@ @require_once(dirname(__FILE__) . '/config/class_FrameworkConfiguration.php'); // Get a new configuration instance -$cfg = FrameworkConfiguration::createFrameworkConfiguration(); +$cfg = FrameworkConfiguration::getInstance(); // CFG: SERVER-PATH $cfg->setConfigEntry('base_path', (dirname(dirname(__FILE__)) . '/')); // DON'T MISS THE TRAILING SLASH!!! diff --git a/inc/config/class_FrameworkConfiguration.php b/inc/config/class_FrameworkConfiguration.php index e7dfb69..2261c0f 100644 --- a/inc/config/class_FrameworkConfiguration.php +++ b/inc/config/class_FrameworkConfiguration.php @@ -51,46 +51,18 @@ class FrameworkConfiguration implements Registerable { // Empty for now } - /** - * "Create" a configuration instance - * - * @param $enableDebug Wether enable debug mode (default: off) - * @return $cfgInstance An instance of this configuration class - */ - public final static function createFrameworkConfiguration ($enableDebug = false) { - /** - * For singleton design pattern because we only need a one-time-run - * through the initial configuration. - */ - if (is_null(self::$cfgInstance)) { - // CFG: ERROR-REPORTING - @error_reporting(E_ALL | E_STRICT); - - /** - * Shall we enable the debug mode? - */ - if ($enableDebug) { - define('DEBUG_MODE', true); - } - - /** - * Crate a config instance - */ - self::$cfgInstance = new FrameworkConfiguration(); - } - - /** - * Return the instance - */ - return self::$cfgInstance; - } - /** * Getter for an instance of this class * * @return $cfgInstance An instance of this class */ public final static function getInstance () { + // is the instance there? + if (is_null(self::$cfgInstance)) { + // Create a config instance + self::$cfgInstance = new FrameworkConfiguration(); + } // END - if + return self::$cfgInstance; }