]> git.mxchange.org Git - core.git/blobdiff - framework/config/class_FrameworkConfiguration.php
Continued:
[core.git] / framework / config / class_FrameworkConfiguration.php
index 2521e3c9f4e755dfe6bad2b3619691dcf650ac86..be9d7d6dc137c73a39f464a1d14873efc3f638b8 100644 (file)
@@ -1,16 +1,14 @@
 <?php
 
 // Own namespace
-namespace CoreFramework\Configuration;
+namespace Org\Mxchange\CoreFramework\Configuration;
 
 // Import framework stuff
-use CoreFramework\Console\Tools\ConsoleTools;
-use CoreFramework\Dns\UnknownHostnameException;
-use CoreFramework\Generic\FrameworkInterface;
-use CoreFramework\Generic\NullPointerException;
-use CoreFramework\Generic\UnsupportedOperationException;
-use CoreFramework\Object\BaseFrameworkSystem;
-use CoreFramework\Registry\Registerable;
+use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
+use Org\Mxchange\CoreFramework\Generic\NullPointerException;
+use Org\Mxchange\CoreFramework\Generic\UnsupportedOperationException;
+use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
+use Org\Mxchange\CoreFramework\Registry\Registerable;
 
 // Import SPL stuff
 use \InvalidArgumentException;
@@ -48,12 +46,7 @@ class FrameworkConfiguration implements Registerable {
         * hard-coded configuration data and might be overwritten/extended by
         * config data from the database.
         */
-       private $config = array();
-
-       /**
-        * The configuration instance itself
-        */
-       private static $configInstance = NULL;
+       private static $config = array();
 
        /**
         * Call-back instance (unused)
@@ -66,11 +59,12 @@ class FrameworkConfiguration implements Registerable {
        const EXCEPTION_CONFIG_VALUE_TYPE_UNSUPPORTED = 0x132;
 
        /**
-        * Private constructor
+        * Default constructor, the configuration entries are static, not the
+        * whole instance.
         *
         * @return      void
         */
-       private function __construct () {
+       public function __construct () {
                // Empty for now
        }
 
@@ -83,50 +77,6 @@ class FrameworkConfiguration implements Registerable {
                return get_class($this);
        }
 
-       /**
-        * Getter for a singleton instance of this class
-        *
-        * @return      $configInstance         A singleton instance of this class
-        */
-       public static final function getSelfInstance () {
-               // is the instance there?
-               if (is_null(self::$configInstance)) {
-                       // Create a config instance
-                       self::$configInstance = new FrameworkConfiguration();
-               } // END - if
-
-               // Return singleton instance
-               return self::$configInstance;
-       }
-
-       /**
-        * Converts dashes to underscores, e.g. useable for configuration entries
-        *
-        * @param       $str    The string with maybe dashes inside
-        * @return      $str    The converted string with no dashed, but underscores
-        * @throws      NullPointerException    If $str is null
-        * @throws      InvalidArgumentException        If $str is empty
-        */
-       private final function convertDashesToUnderscores ($str) {
-               // Is it null?
-               if (is_null($str)) {
-                       // Throw NPE
-                       throw new NullPointerException($this, BaseFrameworkSystem::EXCEPTION_IS_NULL_POINTER);
-               } elseif (!is_string($str)) {
-                       // Entry is empty
-                       throw new InvalidArgumentException(sprintf('str[]=%s is not a string', gettype($str)), self::EXCEPTION_CONFIG_KEY_IS_EMPTY);
-               } elseif ((is_string($str)) && (empty($str))) {
-                       // Entry is empty
-                       throw new InvalidArgumentException('str is empty', self::EXCEPTION_CONFIG_KEY_IS_EMPTY);
-               }
-
-               // Convert them all
-               $str = str_replace('-', '_', $str);
-
-               // Return converted string
-               return $str;
-       }
-
        /**
         * Checks whether the given configuration key is set
         *
@@ -149,7 +99,7 @@ class FrameworkConfiguration implements Registerable {
                }
 
                // Is it set?
-               $isset = ((isset($this->config[$configKey])) || (array_key_exists($configKey, $this->config)));
+               $isset = ((isset(self::$config[$configKey])) || (array_key_exists($configKey, self::$config)));
 
                // Return the result
                return $isset;
@@ -178,7 +128,7 @@ class FrameworkConfiguration implements Registerable {
                }
 
                // Convert dashes to underscore
-               $configKey = $this->convertDashesToUnderscores($configKey);
+               $configKey = BaseFrameworkSystem::convertDashesToUnderscores($configKey);
 
                // Is a valid configuration key provided?
                if (!$this->isConfigurationEntrySet($configKey)) {
@@ -187,7 +137,7 @@ class FrameworkConfiguration implements Registerable {
                } // END - if
 
                // Return the requested value
-               return $this->config[$configKey];
+               return self::$config[$configKey];
        }
 
        /**
@@ -217,14 +167,14 @@ class FrameworkConfiguration implements Registerable {
                }
 
                // Cast to string
-               $configKey = $this->convertDashesToUnderscores($configKey);
+               $configKey = BaseFrameworkSystem::convertDashesToUnderscores($configKey);
 
                // Set the configuration value
                //* NOISY-DEBUG: */ print(__METHOD__ . ':configEntry=' . $configKey . ',configValue[' . gettype($configValue) . ']=' . $configValue . PHP_EOL);
-               $this->config[$configKey] = $configValue;
+               self::$config[$configKey] = $configValue;
 
                // Resort the array
-               ksort($this->config);
+               ksort(self::$config);
        }
 
        /**
@@ -234,7 +184,7 @@ class FrameworkConfiguration implements Registerable {
         */
        public final function getConfigurationArray () {
                // Return it
-               return $this->config;
+               return self::$config;
        }
 
        /**
@@ -261,7 +211,7 @@ class FrameworkConfiguration implements Registerable {
                }
 
                // Convert dashes to underscore
-               $configKey = $this->convertDashesToUnderscores($configKey);
+               $configKey = BaseFrameworkSystem::convertDashesToUnderscores($configKey);
 
                // Is the configuration key there?
                if (!$this->isConfigurationEntrySet($configKey)) {
@@ -270,7 +220,7 @@ class FrameworkConfiguration implements Registerable {
                } // END - if
 
                // Unset it
-               unset($this->config[$configKey]);
+               unset(self::$config[$configKey]);
        }
 
        /**