Continued:
authorRoland Häder <roland@mxchange.org>
Sun, 16 Jul 2017 12:52:03 +0000 (14:52 +0200)
committerRoland Häder <roland@mxchange.org>
Sun, 16 Jul 2017 12:52:03 +0000 (14:52 +0200)
- added sanity-checks on parameters
- no more these server-based (?) tests

Signed-off-by: Roland Häder <roland@mxchange.org>
framework/config/class_FrameworkConfiguration.php
nbproject/project.properties

index 014c08cddf433fa4db50b1887a74031239bf5f2d..aa29d572a79db062e1e1e06cc5d2bbd30bf3834c 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 <?php
+
 // Own namespace
 // Own namespace
+
 namespace CoreFramework\Configuration;
 
 // Import framework stuff
 namespace CoreFramework\Configuration;
 
 // Import framework stuff
@@ -10,6 +12,9 @@ use CoreFramework\Generic\NullPointerException;
 use CoreFramework\Generic\UnsupportedOperationException;
 use CoreFramework\Registry\Registerable;
 
 use CoreFramework\Generic\UnsupportedOperationException;
 use CoreFramework\Registry\Registerable;
 
+// Import SPL stuff
+use \InvalidArgumentException;
+
 /**
  * A class for the configuration stuff implemented in a singleton design paddern
  *
 /**
  * A class for the configuration stuff implemented in a singleton design paddern
  *
@@ -37,6 +42,7 @@ use CoreFramework\Registry\Registerable;
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 class FrameworkConfiguration implements Registerable {
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 class FrameworkConfiguration implements Registerable {
+
        /**
         * The framework's main configuration array which will be initialized with
         * hard-coded configuration data and might be overwritten/extended by
        /**
         * The framework's main configuration array which will be initialized with
         * hard-coded configuration data and might be overwritten/extended by
@@ -55,8 +61,8 @@ class FrameworkConfiguration implements Registerable {
        private $callbackInstance = NULL;
 
        // Some constants for the configuration system
        private $callbackInstance = NULL;
 
        // Some constants for the configuration system
-       const EXCEPTION_CONFIG_KEY_IS_EMPTY           = 0x130;
-       const EXCEPTION_CONFIG_KEY_WAS_NOT_FOUND      = 0x131;
+       const EXCEPTION_CONFIG_KEY_IS_EMPTY = 0x130;
+       const EXCEPTION_CONFIG_KEY_WAS_NOT_FOUND = 0x131;
        const EXCEPTION_CONFIG_VALUE_TYPE_UNSUPPORTED = 0x132;
 
        /**
        const EXCEPTION_CONFIG_VALUE_TYPE_UNSUPPORTED = 0x132;
 
        /**
@@ -84,7 +90,7 @@ class FrameworkConfiguration implements Registerable {
         */
        public static final function getSelfInstance () {
                // is the instance there?
         */
        public static final function getSelfInstance () {
                // is the instance there?
-               if (is_null(self::$configInstance))  {
+               if (is_null(self::$configInstance)) {
                        // Create a config instance
                        self::$configInstance = new FrameworkConfiguration();
                } // END - if
                        // Create a config instance
                        self::$configInstance = new FrameworkConfiguration();
                } // END - if
@@ -98,8 +104,19 @@ class FrameworkConfiguration implements Registerable {
         *
         * @param       $str    The string with maybe dashes inside
         * @return      $str    The converted string with no dashed, but underscores
         *
         * @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) {
         */
        private final function convertDashesToUnderscores ($str) {
+               // Is it null?
+               if (is_null($str)) {
+                       // Throw NPE
+                       throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
+               } elseif (empty($str)) {
+                       // Entry is empty
+                       throw new InvalidArgumentException('str is empty', self::EXCEPTION_CONFIG_KEY_IS_EMPTY);
+               }
+
                // Convert them all
                $str = str_replace('-', '_', $str);
 
                // Convert them all
                $str = str_replace('-', '_', $str);
 
@@ -112,8 +129,19 @@ class FrameworkConfiguration implements Registerable {
         *
         * @param       $zone   The time-zone string (e.g. Europe/Berlin)
         * @return      void
         *
         * @param       $zone   The time-zone string (e.g. Europe/Berlin)
         * @return      void
+        * @throws      NullPointerException    If $zone is NULL
+        * @throws      InvalidArgumentException        If $zone is empty
         */
        public final function setDefaultTimezone ($zone) {
         */
        public final function setDefaultTimezone ($zone) {
+               // Is it null?
+               if (is_null($zone)) {
+                       // Throw NPE
+                       throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
+               } elseif (empty($zone)) {
+                       // Entry is empty
+                       throw new InvalidArgumentException('zone is empty', self::EXCEPTION_CONFIG_KEY_IS_EMPTY);
+               }
+
                // Is PHP version 5.1.0 or higher? Older versions are being ignored
                if (version_compare(phpversion(), '5.1.0', '>=')) {
                        /*
                // Is PHP version 5.1.0 or higher? Older versions are being ignored
                if (version_compare(phpversion(), '5.1.0', '>=')) {
                        /*
@@ -128,9 +156,20 @@ class FrameworkConfiguration implements Registerable {
         * Checks whether the given configuration key is set
         *
         * @param       $configKey      The configuration key we shall check
         * Checks whether the given configuration key is set
         *
         * @param       $configKey      The configuration key we shall check
-        * @return      $isset          Whether the given configuration key is set
+        * @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 ($configKey) {
+               // Is it null?
+               if (is_null($configKey)) {
+                       // Throw NPE
+                       throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
+               } elseif (empty($configKey)) {
+                       // Entry is empty
+                       throw new InvalidArgumentException('configKey is empty', self::EXCEPTION_CONFIG_KEY_IS_EMPTY);
+               }
+
                // Is it set?
                $isset = isset($this->config[$configKey]);
 
                // Is it set?
                $isset = isset($this->config[$configKey]);
 
@@ -143,21 +182,28 @@ class FrameworkConfiguration implements Registerable {
         *
         * @param       $configKey              The configuration element
         * @return      $configValue    The fetched configuration value
         *
         * @param       $configKey              The configuration element
         * @return      $configValue    The fetched configuration value
-        * @throws      ConfigEntryIsEmptyException             If $configKey is empty
-        * @throws      NoConfigEntryException                  If a configuration element was not found
+        * @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 ($configKey) {
+               // Is it null?
+               if (is_null($configKey)) {
+                       // Throw NPE
+                       throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
+               } elseif (empty($configKey)) {
+                       // Entry is empty
+                       throw new InvalidArgumentException('configKey is empty', self::EXCEPTION_CONFIG_KEY_IS_EMPTY);
+               }
+
                // Convert dashes to underscore
                $configKey = self::convertDashesToUnderscores($configKey);
 
                // Is a valid configuration key provided?
                // Convert dashes to underscore
                $configKey = self::convertDashesToUnderscores($configKey);
 
                // Is a valid configuration key provided?
-               if (empty($configKey)) {
-                       // Entry is empty
-                       throw new ConfigEntryIsEmptyException($this, self::EXCEPTION_CONFIG_KEY_IS_EMPTY);
-               } elseif (!$this->isConfigurationEntrySet($configKey)) {
+               if (!$this->isConfigurationEntrySet($configKey)) {
                        // Entry was not found!
                        throw new NoConfigEntryException(array(__CLASS__, $configKey), self::EXCEPTION_CONFIG_KEY_WAS_NOT_FOUND);
                        // Entry was not found!
                        throw new NoConfigEntryException(array(__CLASS__, $configKey), self::EXCEPTION_CONFIG_KEY_WAS_NOT_FOUND);
-               }
+               } // END - if
 
                // Return the requested value
                return $this->config[$configKey];
 
                // Return the requested value
                return $this->config[$configKey];
@@ -169,25 +215,26 @@ 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
         * @param       $configKey      The configuration key we want to add/change
         * @param       $configValue    The configuration value we want to set
         * @return      void
-        * @throws      ConfigEntryIsEmptyException                     If $configKey is empty
+        * @throws      NullPointerException    If $configKey is NULL
+        * @throws      InvalidArgumentException        If $configKey is empty
         * @throws      ConfigValueTypeUnsupportedException     If $configValue has an unsupported variable type
         */
        public final function setConfigEntry ($configKey, $configValue) {
         * @throws      ConfigValueTypeUnsupportedException     If $configValue has an unsupported variable type
         */
        public final function setConfigEntry ($configKey, $configValue) {
-               // Cast to string
-               $configKey = self::convertDashesToUnderscores($configKey);
-
                // Is a valid configuration key key provided?
                if (is_null($configKey)) {
                        // Configuration key is null
                        throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
                } elseif ((empty($configKey)) || (!is_string($configKey))) {
                        // Entry is empty
                // Is a valid configuration key key provided?
                if (is_null($configKey)) {
                        // Configuration key is null
                        throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
                } elseif ((empty($configKey)) || (!is_string($configKey))) {
                        // Entry is empty
-                       throw new ConfigEntryIsEmptyException($this, self::EXCEPTION_CONFIG_KEY_IS_EMPTY);
+                       throw new InvalidArgumentException('configKey is empty', self::EXCEPTION_CONFIG_KEY_IS_EMPTY);
                } elseif ((is_null($configValue)) || (is_array($configValue)) || (is_object($configValue)) || (is_resource($configValue))) {
                        // These cannot be set as this is not intended for configuration values, please use FrameworkArrayObject instead.
                        throw new ConfigValueTypeUnsupportedException(array($this, $configKey, $configValue), self::EXCEPTION_CONFIG_VALUE_TYPE_UNSUPPORTED);
                }
 
                } elseif ((is_null($configValue)) || (is_array($configValue)) || (is_object($configValue)) || (is_resource($configValue))) {
                        // These cannot be set as this is not intended for configuration values, please use FrameworkArrayObject instead.
                        throw new ConfigValueTypeUnsupportedException(array($this, $configKey, $configValue), self::EXCEPTION_CONFIG_VALUE_TYPE_UNSUPPORTED);
                }
 
+               // Cast to string
+               $configKey = self::convertDashesToUnderscores($configKey);
+
                // Set the configuration value
                //* NOISY-DEBUG: */ print(__METHOD__ . ':configEntry=' . $configKey . ',configValue[' . gettype($configValue) . ']=' . $configValue . PHP_EOL);
                $this->config[$configKey] = $configValue;
                // Set the configuration value
                //* NOISY-DEBUG: */ print(__METHOD__ . ':configEntry=' . $configKey . ',configValue[' . gettype($configValue) . ']=' . $configValue . PHP_EOL);
                $this->config[$configKey] = $configValue;
@@ -212,9 +259,19 @@ class FrameworkConfiguration implements Registerable {
         *
         * @param       $configKey      Configuration key to unset
         * @return      void
         *
         * @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) {
         * @throws      NoConfigEntryException  If a configuration element was not found
         */
        public final function unsetConfigEntry ($configKey) {
+               if (is_null($configKey)) {
+                       // Configuration key is null
+                       throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
+               } elseif ((empty($configKey)) || (!is_string($configKey))) {
+                       // Entry is empty
+                       throw new InvalidArgumentException('configKey is empty', self::EXCEPTION_CONFIG_KEY_IS_EMPTY);
+               }
+
                // Convert dashes to underscore
                $configKey = self::convertDashesToUnderscores($configKey);
 
                // Convert dashes to underscore
                $configKey = self::convertDashesToUnderscores($configKey);
 
@@ -421,10 +478,10 @@ class FrameworkConfiguration implements Registerable {
        public function equals (FrameworkInterface $objectInstance) {
                // Now test it
                $equals = ((
        public function equals (FrameworkInterface $objectInstance) {
                // Now test it
                $equals = ((
-                       $this->__toString() === $objectInstance->__toString()
-               ) && (
-                       $this->hashCode() === $objectInstance->hashCode()
-               ));
+                               $this->__toString() === $objectInstance->__toString()
+                               ) && (
+                               $this->hashCode() === $objectInstance->hashCode()
+                               ));
 
                // Return the result
                return $equals;
 
                // Return the result
                return $equals;
index 2d50fcf3612daf912cb4b38a5148f0535a8486b2..77359c66b24f4ecce058e4499a054abe8f2d6664 100644 (file)
@@ -25,7 +25,6 @@ include.path=\
     ${php.global.include.path}
 php.version=PHP_56
 project.license=gpl30
     ${php.global.include.path}
 php.version=PHP_56
 project.license=gpl30
-selenium.src.dir=${file.reference.core-tests}
 source.encoding=UTF-8
 src.dir=.
 tags.asp=false
 source.encoding=UTF-8
 src.dir=.
 tags.asp=false