]> git.mxchange.org Git - core.git/blobdiff - framework/config/class_FrameworkConfiguration.php
Continued:
[core.git] / framework / config / class_FrameworkConfiguration.php
index be9d7d6dc137c73a39f464a1d14873efc3f638b8..132fba6ac0bea54717dd70c90a339e75d13fa3b9 100644 (file)
@@ -4,11 +4,12 @@
 namespace Org\Mxchange\CoreFramework\Configuration;
 
 // Import framework stuff
+use Org\Mxchange\CoreFramework\Configuration\NoConfigEntryException;
 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;
+use Org\Mxchange\CoreFramework\Utils\String\StringUtils;
 
 // Import SPL stuff
 use \InvalidArgumentException;
@@ -22,7 +23,7 @@ use \InvalidArgumentException;
  * @see                        ClassLoader
  * @author             Roland Haeder <webmaster@shipsimu.org>
  * @version            1.0.1
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 Core Developer Team
  * @license            GNU GPL 3.0 or any newer version
  * @link               http://www.shipsimu.org
  *
@@ -46,7 +47,7 @@ class FrameworkConfiguration implements Registerable {
         * hard-coded configuration data and might be overwritten/extended by
         * config data from the database.
         */
-       private static $config = array();
+       private static $config = [];
 
        /**
         * Call-back instance (unused)
@@ -82,18 +83,11 @@ class FrameworkConfiguration implements Registerable {
         *
         * @param       $configKey      The configuration key we shall check
         * @return      $isset  Whether the given configuration key is set
-        * @throws      NullPointerException    If $configKey is NULL
         * @throws      InvalidArgumentException        If $configKey is empty
         */
-       public function isConfigurationEntrySet ($configKey) {
+       public function isConfigurationEntrySet (string $configKey) {
                // Is it null?
-               if (is_null($configKey)) {
-                       // Throw NPE
-                       throw new NullPointerException($this, BaseFrameworkSystem::EXCEPTION_IS_NULL_POINTER);
-               } elseif (!is_string($configKey)) {
-                       // Is not a string
-                       throw new InvalidArgumentException(sprintf('configKey[]=%s is not a string', gettype($configKey)), self::EXCEPTION_CONFIG_KEY_IS_EMPTY);
-               } elseif ((is_string($configKey)) && (empty($configKey))) {
+               if (empty($configKey)) {
                        // Entry is empty
                        throw new InvalidArgumentException('configKey is empty', self::EXCEPTION_CONFIG_KEY_IS_EMPTY);
                }
@@ -110,31 +104,24 @@ class FrameworkConfiguration implements Registerable {
         *
         * @param       $configKey              The configuration element
         * @return      $configValue    The fetched configuration value
-        * @throws      NullPointerException    If $configKey is NULL
         * @throws      InvalidArgumentException        If $configKey is empty
         * @throws      NoConfigEntryException          If a configuration element was not found
         */
-       public function getConfigEntry ($configKey) {
+       public function getConfigEntry (string $configKey) {
                // Is it null?
-               if (is_null($configKey)) {
-                       // Throw NPE
-                       throw new NullPointerException($this, BaseFrameworkSystem::EXCEPTION_IS_NULL_POINTER);
-               } elseif (!is_string($configKey)) {
-                       // Is not a string
-                       throw new InvalidArgumentException(sprintf('configKey[]=%s is not a string', gettype($configKey)), self::EXCEPTION_CONFIG_KEY_IS_EMPTY);
-               } elseif ((is_string($configKey)) && (empty($configKey))) {
+               if (empty($configKey)) {
                        // Entry is empty
                        throw new InvalidArgumentException('configKey is empty', self::EXCEPTION_CONFIG_KEY_IS_EMPTY);
                }
 
                // Convert dashes to underscore
-               $configKey = BaseFrameworkSystem::convertDashesToUnderscores($configKey);
+               $configKey = StringUtils::convertDashesToUnderscores($configKey);
 
                // Is a valid configuration key provided?
                if (!$this->isConfigurationEntrySet($configKey)) {
                        // Entry was not found!
                        throw new NoConfigEntryException(array(__CLASS__, $configKey), self::EXCEPTION_CONFIG_KEY_WAS_NOT_FOUND);
-               } // END - if
+               }
 
                // Return the requested value
                return self::$config[$configKey];
@@ -146,19 +133,12 @@ class FrameworkConfiguration implements Registerable {
         * @param       $configKey      The configuration key we want to add/change
         * @param       $configValue    The configuration value we want to set
         * @return      void
-        * @throws      NullPointerException    If $configKey is NULL
         * @throws      InvalidArgumentException        If $configKey is empty
         * @throws      InvalidArgumentException        If $configValue has an unsupported variable type
         */
-       public final function setConfigEntry ($configKey, $configValue) {
+       public final function setConfigEntry (string $configKey, $configValue) {
                // Is a valid configuration key key provided?
-               if (is_null($configKey)) {
-                       // Configuration key is null
-                       throw new NullPointerException($this, BaseFrameworkSystem::EXCEPTION_IS_NULL_POINTER);
-               } elseif (!is_string($configKey)) {
-                       // Is not a string
-                       throw new InvalidArgumentException(sprintf('configKey[]=%s is not a string', gettype($configKey)), self::EXCEPTION_CONFIG_KEY_IS_EMPTY);
-               } elseif ((is_string($configKey)) && (empty($configKey))) {
+               if (empty($configKey)) {
                        // Entry is empty
                        throw new InvalidArgumentException('configKey is empty', self::EXCEPTION_CONFIG_KEY_IS_EMPTY);
                } elseif ((is_array($configValue)) || (is_object($configValue)) || (is_resource($configValue))) {
@@ -167,7 +147,7 @@ class FrameworkConfiguration implements Registerable {
                }
 
                // Cast to string
-               $configKey = BaseFrameworkSystem::convertDashesToUnderscores($configKey);
+               $configKey = StringUtils::convertDashesToUnderscores($configKey);
 
                // Set the configuration value
                //* NOISY-DEBUG: */ print(__METHOD__ . ':configEntry=' . $configKey . ',configValue[' . gettype($configValue) . ']=' . $configValue . PHP_EOL);
@@ -193,60 +173,29 @@ class FrameworkConfiguration implements Registerable {
         *
         * @param       $configKey      Configuration key to unset
         * @return      void
-        * @throws      NullPointerException    If $configKey is NULL
         * @throws      InvalidArgumentException        If $configKey is empty
         * @throws      NoConfigEntryException  If a configuration element was not found
         */
-       public final function unsetConfigEntry ($configKey) {
+       public final function unsetConfigEntry (string $configKey) {
                // Validate parameters
-               if (is_null($configKey)) {
-                       // Configuration key is null
-                       throw new NullPointerException($this, BaseFrameworkSystem::EXCEPTION_IS_NULL_POINTER);
-               } elseif (!is_string($configKey)) {
-                       // Entry is empty
-                       throw new InvalidArgumentException(sprintf('configKey[]=%s is not a string', gettype($configKey)), self::EXCEPTION_CONFIG_KEY_IS_EMPTY);
-               } elseif ((is_string($configKey)) && (empty($configKey))) {
+               if (empty($configKey)) {
                        // Entry is empty
                        throw new InvalidArgumentException('configKey is empty', self::EXCEPTION_CONFIG_KEY_IS_EMPTY);
                }
 
                // Convert dashes to underscore
-               $configKey = BaseFrameworkSystem::convertDashesToUnderscores($configKey);
+               $configKey = StringUtils::convertDashesToUnderscores($configKey);
 
                // Is the configuration key there?
                if (!$this->isConfigurationEntrySet($configKey)) {
                        // Entry was not found!
                        throw new NoConfigEntryException(array(__CLASS__, $configKey), self::EXCEPTION_CONFIG_KEY_WAS_NOT_FOUND);
-               } // END - if
+               }
 
                // Unset it
                unset(self::$config[$configKey]);
        }
 
-       /**
-        * Getter for field name
-        *
-        * @param       $fieldName              Field name which we shall get
-        * @return      $fieldValue             Field value from the user
-        * @throws      NullPointerException    If the result instance is null
-        */
-       public final function getField ($fieldName) {
-               // The super interface "FrameworkInterface" requires this
-               throw new UnsupportedOperationException(array($this, __FUNCTION__), BaseFrameworkSystem::EXCEPTION_UNSPPORTED_OPERATION);
-       }
-
-       /**
-        * Checks if given field is set
-        *
-        * @param       $fieldName      Field name to check
-        * @return      $isSet          Whether the given field name is set
-        * @throws      NullPointerException    If the result instance is null
-        */
-       public function isFieldSet ($fieldName) {
-               // The super interface "FrameworkInterface" requires this
-               throw new UnsupportedOperationException(array($this, __FUNCTION__), BaseFrameworkSystem::EXCEPTION_UNSPPORTED_OPERATION);
-       }
-
        /**
         * Generates a code for hashes from this class
         *
@@ -285,4 +234,28 @@ class FrameworkConfiguration implements Registerable {
                $this->callbackInstance = $callbackInstance;
        }
 
+       /**
+        * Getter for field name
+        *
+        * @param       $fieldName              Field name which we shall get
+        * @return      $fieldValue             Field value from the user
+        * @throws      NullPointerException    If the result instance is null
+        */
+       public final function getField (string $fieldName) {
+               // The super interface "FrameworkInterface" requires this
+               throw new UnsupportedOperationException(array($this, __FUNCTION__), BaseFrameworkSystem::EXCEPTION_UNSPPORTED_OPERATION);
+       }
+
+       /**
+        * Checks if given field is set
+        *
+        * @param       $fieldName      Field name to check
+        * @return      $isSet          Whether the given field name is set
+        * @throws      NullPointerException    If the result instance is null
+        */
+       public function isFieldSet (string $fieldName) {
+               // The super interface "FrameworkInterface" requires this
+               throw new UnsupportedOperationException(array($this, __FUNCTION__), BaseFrameworkSystem::EXCEPTION_UNSPPORTED_OPERATION);
+       }
+
 }