Continued:
[core.git] / framework / main / classes / criteria / class_BaseCriteria.php
index cf250a3f944c76794e083eb5160217d70e10304f..3582f38a025ddafdceb5d10d4a53306a0abef05c 100644 (file)
@@ -3,16 +3,23 @@
 namespace Org\Mxchange\CoreFramework\Criteria;
 
 // Import framework stuff
+use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
 use Org\Mxchange\CoreFramework\Criteria\Search\SearchCriteria;
+use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
 use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
-use Org\Mxchange\CoreFramework\String\Utils\StringUtils;
+use Org\Mxchange\CoreFramework\Utils\Strings\StringUtils;
+
+// Import SPL stuff
+use \BadMethodCallException;
+use \InvalidArgumentException;
+use \UnexpectedValueException;
 
 /**
  * A general crtieria class
  *
  * @author             Roland Haeder <webmaster@shipsimu.org>
  * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2023 Core Developer Team
  * @license            GNU GPL 3.0 or any newer version
  * @link               http://www.shipsimu.org
  *
@@ -31,9 +38,14 @@ use Org\Mxchange\CoreFramework\String\Utils\StringUtils;
  */
 abstract class BaseCriteria extends BaseFrameworkSystem implements Criteria {
        /**
-        * Wrapper class name stored in config entry
+        * Frontend class name stored in config entry
+        */
+       private $frontendConfigEntry = '';
+
+       /**
+        * All supported criteria types
         */
-       private $wrapperConfigEntry = '';
+       private static $CRITERIA_TYPES = [];
 
        /**
         * Protected constructor
@@ -41,15 +53,48 @@ abstract class BaseCriteria extends BaseFrameworkSystem implements Criteria {
         * @param       $className      Name of the class
         * @return      void
         */
-       protected function __construct ($className) {
+       protected function __construct (string $className) {
                // Call parent constructor
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-CRITERIA: className=%s - CONSTRUCTED!', $className));
                parent::__construct($className);
 
+               // Initialize valid criteria types array
+               self::$CRITERIA_TYPES = [Criteria::CRITERIA_TYPE_DEFAULT, Criteria::CRITERIA_TYPE_CHOICE, Criteria::CRITERIA_TYPE_EXCLUDE];
+
                // Initialize all criteria arrays
-               foreach (array('default', 'choice', 'exclude') as $criteriaType) {
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-CRITERIA: self::CRITERIA_TYPES()=%d', count(self::$CRITERIA_TYPES)));
+               foreach (self::$CRITERIA_TYPES as $criteriaType) {
                        // Init it
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-CRITERIA: Invoking this->initGenericArrayKey(criteria,%s,entries) ...', $criteriaType));
                        $this->initGenericArrayKey('criteria', $criteriaType, 'entries');
-               } // END - foreach
+               }
+
+               // Trace message
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-CRITERIA: EXIT!');
+       }
+
+       /**
+        * Count the criteria, e.g. useful to find out if a database query has no
+        * limitation (search criteria).
+        *
+        * @param       $criteriaType   Type of this criteria, can be one of 'default' (default), 'choice' or 'exclude'
+        * @return      $count  Count of all criteria entries
+        * @throws      InvalidArgumentException        If a parameter is not valid
+        */
+       protected final function count (string $criteriaType = Criteria::CRITERIA_TYPE_DEFAULT) {
+               // Check parameter
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-CRITERIA: criteriaType=%s - CALLED!', strtoupper($criteriaType), $criteriaType));
+               if (empty($criteriaType)) {
+                       // Throw it again
+                       throw new InvalidArgumentException('Parameter "criteriaType" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
+               } elseif (!in_array($criteriaType, self::$CRITERIA_TYPES)) {
+                       // Throw it again
+                       throw new InvalidArgumentException(sprintf('criteriaType=%s is not supported', $criteriaType));
+               }
+
+               // Invoke inner method
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-CRITERIA: Invoking this->countGenericArrayGroup(criteria, %s) ... - EXIT!', strtoupper($criteriaType), $criteriaType));
+               return $this->countGenericArrayGroup('criteria', $criteriaType);
        }
 
        /**
@@ -57,58 +102,93 @@ abstract class BaseCriteria extends BaseFrameworkSystem implements Criteria {
         *
         * @param       $criteriaType   Type of this criteria, can be one of 'default' (default), 'choice' or 'exclude'
         * @param       $criteriaKey    Criteria key
-        * @return      $isSet                  Whether key is set
+        * @return      $isset                  Whether key is set
+        * @throws      InvalidArgumentException        If a parameter is not valid
+        * @throws      UnexpectedValueException        If a parameter contains an unexpected/unsupported value
         */
-       public function isKeySet ($criteriaType, $criteriaKey) {
-               // Make sure no 'my-' or 'my_' passes this point
-               assert((strpos($criteriaKey, 'my-') === false) && (strpos($criteriaKey, 'my_') === false));
+       public function isKeySet (string $criteriaType, string $criteriaKey) {
+               // Check parameters
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-CRITERIA: criteriaType=%s,criteriaKey=%s - CALLED!', strtoupper($criteriaType), $criteriaType, $criteriaKey));
+               if (empty($criteriaType)) {
+                       // Throw it again
+                       throw new InvalidArgumentException('Parameter "criteriaType" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
+               } elseif (!in_array($criteriaType, self::$CRITERIA_TYPES)) {
+                       // Throw it again
+                       throw new UnexpectedValueException(sprintf('criteriaType=%s is not supported', $criteriaType), FrameworkInterface::EXCEPTION_UNEXPECTED_VALUE);
+               } elseif (empty($criteriaKey)) {
+                       // Throw it again
+                       throw new InvalidArgumentException('Parameter "criteriaKey" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
+               } elseif ((strpos($criteriaKey, 'my-') !== false) || (strpos($criteriaKey, 'my_') !== false)) {
+                       // Throw it again
+                       throw new InvalidArgumentException(sprintf('criteriaKey=%s has illegal prefix "my"', $criteriaKey));
+               }
 
                // Determine it
-               $isSet = $this->isGenericArrayElementSet('criteria', $criteriaType, 'entries', $criteriaKey);
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('%s-CRITERIA: Invoking this->isGenericArrayElementSet(criteria,%s,entries,%s) ...', strtoupper($criteriaType), $criteriaType, $criteriaKey));
+               $isset = $this->isGenericArrayElementSet('criteria', $criteriaType, 'entries', $criteriaKey);
 
                // Return it
-               return $isSet;
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-CRITERIA: isset=%d - EXIT!', strtoupper($criteriaType), intval($isset)));
+               return $isset;
        }
 
        /**
         * Checks whether given key is set for 'choice' type
         *
         * @param       $criteriaKey    Criteria key
-        * @return      $isSet                  Whether key is set
+        * @return      $isset                  Whether key is set
+        * @throws      InvalidArgumentException        If a parameter is not valid
         */
-       public function isChoiceKeySet ($criteriaKey) {
-               // Call inner method
-               return $this->isKeySet('choice', $criteriaKey);
+       public function isChoiceKeySet (string $criteriaKey) {
+               // Validate parameter
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-CRITERIA: criteriaKey=%s - CALLED!', $criteriaKey));
+               if (empty($criteriaKey)) {
+                       // Throw it again
+                       throw new InvalidArgumentException('Parameter "criteriaKey" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
+               }
+
+               // Invoke inner method
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-CRITERIA: Invoking this->isKeySet(%s,%s) ...', Criteria::CRITERIA_TYPE_CHOICE, $criteriaKey));
+               return $this->isKeySet(Criteria::CRITERIA_TYPE_CHOICE, $criteriaKey);
        }
 
        /**
         * Checks whether given key is set for 'exclude' type
         *
         * @param       $criteriaKey    Criteria key
-        * @return      $isSet                  Whether key is set
+        * @return      $isset                  Whether key is set
+        * @throws      InvalidArgumentException        If a parameter is not valid
         */
-       public function isExcludeKeySet ($criteriaKey) {
-               // Call inner method
-               return $this->isKeySet('exclude', $criteriaKey);
+       public function isExcludeKeySet (string $criteriaKey) {
+               // Validate parameter
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-CRITERIA: criteriaKey=%s - CALLED!', $criteriaKey));
+               if (empty($criteriaKey)) {
+                       // Throw it again
+                       throw new InvalidArgumentException('Parameter "criteriaKey" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
+               }
+
+               // Invoke inner method
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-CRITERIA: Invoking this->isKeySet(%s,%s) ... - EXIT!', Criteria::CRITERIA_TYPE_EXCLUDE, $criteriaKey));
+               return $this->isKeySet(Criteria::CRITERIA_TYPE_EXCLUDE, $criteriaKey);
        }
 
        /**
-        * Setter for wrapper class name
+        * Setter for frontend class name
         *
-        * @param       $wrapperConfigEntry             Configuration entry which hold the wrapper class' name
+        * @param       $frontendConfigEntry            Configuration entry which hold the frontend class' name
         * @return      void
         */
-       public final function setWrapperConfigEntry ($wrapperConfigEntry) {
-               $this->wrapperConfigEntry = (string) $wrapperConfigEntry;
+       public final function setFrontendConfigEntry (string $frontendConfigEntry) {
+               $this->frontendConfigEntry = $frontendConfigEntry;
        }
 
        /**
-        * Getter for wrapper class name
+        * Getter for frontend class name
         *
-        * @return      $wrapperConfigEntry             Configuration entry which hold the wrapper class' name
+        * @return      $frontendConfigEntry            Configuration entry which hold the frontend class' name
         */
-       public final function getWrapperConfigEntry () {
-               return $this->wrapperConfigEntry;
+       public final function getFrontendConfigEntry () {
+               return $this->frontendConfigEntry;
        }
 
        /**
@@ -116,8 +196,22 @@ abstract class BaseCriteria extends BaseFrameworkSystem implements Criteria {
         *
         * @param       $criteriaType   Type of this criteria, can be one of 'default' (default), 'choice' or 'exclude'
         * @return      $criteria
+        * @throws      InvalidArgumentException        If a parameter is not valid
+        * @throws      UnexpectedValueException        If a parameter contains an unexpected/unsupported value
         */
-       public final function getCriteriaArray ($criteriaType = 'default') {
+       public final function getCriteriaArray (string $criteriaType = Criteria::CRITERIA_TYPE_DEFAULT) {
+               // Check parameters
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-CRITERIA: criteriaType=%s - CALLED!', strtoupper($criteriaType), $criteriaType));
+               if (empty($criteriaType)) {
+                       // Throw it again
+                       throw new InvalidArgumentException('Parameter "criteriaType" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
+               } elseif (!in_array($criteriaType, self::$CRITERIA_TYPES)) {
+                       // Throw it again
+                       throw new UnexpectedValueException(sprintf('criteriaType=%s is not supported', $criteriaType), FrameworkInterface::EXCEPTION_UNEXPECTED_VALUE);
+               }
+
+               // Invoke inner method
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-CRITERIA: Invoking this->getGenericArrayKey(criteria,%s,entries) ... - EXIT!', strtoupper($criteriaType), $criteriaType));
                return $this->getGenericArrayKey('criteria', $criteriaType, 'entries');
        }
 
@@ -127,7 +221,8 @@ abstract class BaseCriteria extends BaseFrameworkSystem implements Criteria {
         * @return      $criteria
         */
        public final function getCriteriaChoiceArray () {
-               return $this->getCriteriaArray('choice');
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-CRITERIA: CALLED!', strtoupper($criteriaType)));
+               return $this->getCriteriaArray(Criteria::CRITERIA_TYPE_CHOICE);
        }
 
        /**
@@ -136,7 +231,8 @@ abstract class BaseCriteria extends BaseFrameworkSystem implements Criteria {
         * @return      $criteria
         */
        public final function getCriteriaExcludeArray () {
-               return $this->getCriteriaArray('exclude');
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-CRITERIA: CALLED!');
+               return $this->getCriteriaArray(Criteria::CRITERIA_TYPE_EXCLUDE);
        }
 
        /**
@@ -145,18 +241,31 @@ abstract class BaseCriteria extends BaseFrameworkSystem implements Criteria {
         * @param       $criteriaKey    Criteria key to unset
         * @return      void
         */
-       public final function unsetCriteria ($criteriaKey) {
-               // Make sure no 'my-' or 'my_' passes this point
-               assert((strpos($criteriaKey, 'my-') === false) && (strpos($criteriaKey, 'my_') === false));
+       public final function unsetCriteria (string $criteriaKey) {
+               // Check parameter
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-CRITERIA: criteriaKey=%s - CALLED!', $criteriaKey));
+               if (empty($criteriaKey)) {
+                       // Throw it again
+                       throw new InvalidArgumentException('Parameter "criteriaKey" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
+               } elseif ((strpos($criteriaKey, 'my-') !== false) || (strpos($criteriaKey, 'my_') !== false)) {
+                       // Throw it again
+                       throw new InvalidArgumentException(sprintf('criteriaKey=%s has illegal prefix "my"', $criteriaKey));
+               }
 
                // Convert dashes to underscore
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-CRITERIA: Invoking StringUtils::convertDashesToUnderscores(%s) ...', strtoupper($criteriaType), $criteriaKey));
                $criteriaKey = StringUtils::convertDashesToUnderscores($criteriaKey);
 
                // "Walk" through all criterias
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('%s-CRITERIA: criteriaKey=%s', strtoupper($criteriaType), $criteriaKey));
                foreach ($this->getGenericArray('criteria') as $criteriaType => $dummy) {
                        // Remove it
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-CRITERIA: Removing criteriaType=%s,criteriaKey=%s ...', strtoupper($criteriaType), $criteriaType, $criteriaKey));
                        $this->unsetGenericArrayElement('criteria', $criteriaType, 'entries', $criteriaKey);
-               } // END - foreach
+               }
+
+               // Trace message
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-CRITERIA: EXIT!');
        }
 
        /**
@@ -167,22 +276,39 @@ abstract class BaseCriteria extends BaseFrameworkSystem implements Criteria {
         * @param       $criteriaValue  Criteria value
         * @param       $criteriaType   Type of this criteria, can be one of 'default' (default), 'choice' or 'exclude'
         * @return      void
+        * @throws      InvalidArgumentException        If a parameter is not valid
+        * @throws      UnexpectedValueException        If a parameter contains an unexpected/unsupported value
         */
-       public final function addCriteria ($criteriaKey, $criteriaValue, $criteriaType = 'default') {
-               // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($criteriaType) . '-CRITERIA[' . __METHOD__ . ':' . __LINE__ . ']: criteriaKey=' . $criteriaKey . ',criteriaValue=' . $criteriaValue . ',criteriaType=' . $criteriaType . ' - CALLED!');
-
-               // Make sure no 'my-' or 'my_' passes this point
-               assert((strpos($criteriaKey, 'my-') === false) && (strpos($criteriaKey, 'my_') === false) && (!is_bool($criteriaValue)));
+       public final function addCriteria (string $criteriaKey, $criteriaValue, string $criteriaType = Criteria::CRITERIA_TYPE_DEFAULT) {
+               // Check parameter
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-CRITERIA: criteriaKey=%s,criteriaValue[]=%s,criteriaType=%s - CALLED!', strtoupper($criteriaType), $criteriaKey, gettype($criteriaValue), $criteriaType));
+               if (empty($criteriaKey)) {
+                       // Throw IAE
+                       throw new InvalidArgumentException('Parameter "criteriaKey" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
+               } elseif ((strpos($criteriaKey, 'my-') !== false) || (strpos($criteriaKey, 'my_') !== false)) {
+                       // Throw it again
+                       throw new InvalidArgumentException(sprintf('criteriaKey=%s has illegal prefix "my"', $criteriaKey));
+               } elseif (is_array($criteriaValue) || is_bool($criteriaValue) || is_object($criteriaValue) || is_resource($criteriaValue)) {
+                       // Throw it again
+                       throw new InvalidArgumentException(sprintf('value[]=%s is not supported', gettype($criteriaValue)));
+               } elseif (empty($criteriaType)) {
+                       // Throw it again
+                       throw new InvalidArgumentException('Parameter "criteriaType" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
+               } elseif (!in_array($criteriaType, self::$CRITERIA_TYPES)) {
+                       // Throw it again
+                       throw new UnexpectedValueException(sprintf('criteriaType=%s is not supported', $criteriaType), FrameworkInterface::EXCEPTION_UNEXPECTED_VALUE);
+               }
 
                // Convert dashes to underscore
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-CRITERIA: Invoking StringUtils::convertDashesToUnderscores(%s) ...', strtoupper($criteriaType), $criteriaKey));
                $criteriaKey = StringUtils::convertDashesToUnderscores($criteriaKey);
 
-               // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($criteriaType) . '(' . $this->__toString() . ')-CRITERIA[' . __METHOD__ . ':' . __LINE__ . ']: criteriaKey=' . $criteriaKey);
+               // Set it
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-CRITERIA: Invoking this->setGenericArrayElement(criteria,%s,entries,%s,criteriaValue[]=%s) ...', strtoupper($criteriaType), $criteriaType, $criteriaKey, gettype($criteriaValue)));
+               $this->setGenericArrayElement('criteria', $criteriaType, 'entries', $criteriaKey, $criteriaValue);
 
-               // Append it
-               $this->appendStringToGenericArrayElement('criteria', $criteriaType, 'entries', $criteriaKey, $criteriaValue);
+               // Trace message
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-CRITERIA: EXIT!', strtoupper($criteriaType)));
        }
 
        /**
@@ -193,22 +319,39 @@ abstract class BaseCriteria extends BaseFrameworkSystem implements Criteria {
         * @param       $criteriaValue  Criteria value
         * @param       $criteriaType   Type of this criteria, can be one of 'default' (default), 'choice' or 'exclude'
         * @return      void
+        * @throws      InvalidArgumentException        If a parameter is not valid
+        * @throws      UnexpectedValueException        If a parameter contains an unexpected/unsupported value
         */
-       public final function setCriteria ($criteriaKey, $criteriaValue, $criteriaType = 'default') {
-               // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($criteriaType) . '-CRITERIA[' . __METHOD__ . ':' . __LINE__ . ']: criteriaKey=' . $criteriaKey . ',criteriaValue=' . $criteriaValue . ',criteriaType=' . $criteriaType . ' - CALLED!');
-
-               // Make sure no 'my-' or 'my_' passes this point
-               assert((strpos($criteriaKey, 'my-') === false) && (strpos($criteriaKey, 'my_') === false) && (!is_bool($criteriaValue)));
+       public final function setCriteria (string $criteriaKey, $criteriaValue, string $criteriaType = Criteria::CRITERIA_TYPE_DEFAULT) {
+               // Check parameter
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-CRITERIA: criteriaKey=%s,criteriaValue[]=%s$criteriaValue,criteriaType=%s - CALLED!', strtoupper($criteriaType), $criteriaKey, gettype($criteriaValue), $criteriaType));
+               if (empty($criteriaKey)) {
+                       // Throw IAE
+                       throw new InvalidArgumentException('Parameter "criteriaKey" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
+               } elseif ((strpos($criteriaKey, 'my-') !== false) || (strpos($criteriaKey, 'my_') !== false)) {
+                       // Throw it again
+                       throw new InvalidArgumentException(sprintf('criteriaKey=%s has illegal prefix "my"', $criteriaKey));
+               } elseif (is_array($criteriaValue) || is_bool($criteriaValue) || is_object($criteriaValue) || is_resource($criteriaValue)) {
+                       // Throw it again
+                       throw new InvalidArgumentException(sprintf('value[]=%s is not supported', gettype($criteriaValue)));
+               } elseif (empty($criteriaType)) {
+                       // Throw it again
+                       throw new InvalidArgumentException('Parameter "criteriaType" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
+               } elseif (!in_array($criteriaType, self::$CRITERIA_TYPES)) {
+                       // Throw it again
+                       throw new UnexpectedValueException(sprintf('criteriaType=%s is not supported', $criteriaType), FrameworkInterface::EXCEPTION_UNEXPECTED_VALUE);
+               }
 
                // Convert dashes to underscore
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-CRITERIA: Invoking StringUtils::convertDashesToUnderscores(%s) ...', strtoupper($criteriaType), $criteriaKey));
                $criteriaKey = StringUtils::convertDashesToUnderscores($criteriaKey);
 
-               // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($criteriaType) . '(' . $this->__toString() . ')-CRITERIA[' . __METHOD__ . ':' . __LINE__ . ']: criteriaKey=' . $criteriaKey);
-
                // Set it
-               $this->setStringGenericArrayElement('criteria', $criteriaType, 'entries', $criteriaKey, $criteriaValue);
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-CRITERIA: Invoking this->setGenericArrayElement(criteria,%s,entries,%s,criteriaValue[]=%s) ...', strtoupper($criteriaType), $criteriaKey, gettype($criteriaValue)));
+               $this->setGenericArrayElement('criteria', $criteriaType, 'entries', $criteriaKey, $criteriaValue);
+
+               // Trace message
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-CRITERIA: EXIT!');
        }
 
        /**
@@ -218,16 +361,33 @@ abstract class BaseCriteria extends BaseFrameworkSystem implements Criteria {
         * @param       $criteriaKey    Criteria key
         * @param       $criteriaValue  Criteria value
         * @return      void
+        * @throws      InvalidArgumentException        If a parameter is not valid
+        * @throws      UnexpectedValueException        If $criteriaValue has an unexpected type
         */
-       public final function addChoiceCriteria ($criteriaKey, $criteriaValue) {
-               // Make sure no 'my-' or 'my_' passes this point
-               assert((strpos($criteriaKey, 'my-') === false) && (strpos($criteriaKey, 'my_') === false) && (!is_bool($criteriaValue)));
+       public final function addChoiceCriteria (string $criteriaKey, $criteriaValue) {
+               // Check parameter
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-CRITERIA: criteriaKey=%s,criteriaValue[]=%s - CALLED!', $criteriaKey, gettype($criteriaValue)));
+               if (empty($criteriaKey)) {
+                       // Throw IAE
+                       throw new InvalidArgumentException('Parameter "criteriaKey" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
+               } elseif ((strpos($criteriaKey, 'my-') !== false) || (strpos($criteriaKey, 'my_') !== false)) {
+                       // Throw it again
+                       throw new InvalidArgumentException(sprintf('criteriaKey=%s has illegal prefix "my"', $criteriaKey));
+               } elseif (is_array($criteriaValue) || is_bool($criteriaValue) || is_object($criteriaValue) || is_resource($criteriaValue)) {
+                       // Throw UAE
+                       throw new UnexpectedValueException(sprintf('criteriaValue[]=%s is not accepted', gettype($criteriaValue)), FrameworkInterface::EXCEPTION_UNEXPECTED_VALUE);
+               }
 
-               // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($criteriaType) . '(' . $this->__toString() . ')-CRITERIA[' . __METHOD__ . ':' . __LINE__ . ']: criteriaKey=' . $criteriaKey . ',criteriaValue=' . $criteriaValue);
+               // Convert dashes to underscore
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-CRITERIA: Invoking StringUtils::convertDashesToUnderscores(%s) ...', $criteriaKey));
+               $criteriaKey = StringUtils::convertDashesToUnderscores($criteriaKey);
 
                // Add it
-               $this->pushValueToGenericArrayElement('criteria', 'choice', 'entries', StringUtils::convertDashesToUnderscores($criteriaKey), (string) $criteriaValue);
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-CRITERIA: Invoking this->pushValueToGenericArrayElement(criteria,%s,entries,%s,criteriaValue[]=%s) ...', Criteria::CRITERIA_TYPE_CHOICE, $criteriaKey, gettype($criteriaValue)));
+               $this->pushValueToGenericArrayElement('criteria', Criteria::CRITERIA_TYPE_CHOICE, 'entries', $criteriaKey, $criteriaValue);
+
+               // Trace message
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-CRITERIA: EXIT!');
        }
 
        /**
@@ -237,10 +397,29 @@ abstract class BaseCriteria extends BaseFrameworkSystem implements Criteria {
         * @param       $criteriaKey    Criteria key
         * @param       $criteriaValue  Criteria value
         * @return      void
+        * @throws      InvalidArgumentException        If a parameter is not valid
+        * @throws      UnexpectedValueException        If $criteriaValue has an unexpected type
         */
-       public final function addExcludeCriteria ($criteriaKey, $criteriaValue) {
+       public final function addExcludeCriteria (string $criteriaKey, $criteriaValue) {
+               // Check parameter
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-CRITERIA: criteriaKey=%s,criteriaValue[%s]=%s - CALLED!', $criteriaKey, gettype($criteriaValue), $criteriaValue));
+               if (empty($criteriaKey)) {
+                       // Throw IAE
+                       throw new InvalidArgumentException('Parameter "criteriaKey" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
+               } elseif ((strpos($criteriaKey, 'my-') !== false) || (strpos($criteriaKey, 'my_') !== false)) {
+                       // Throw it again
+                       throw new InvalidArgumentException(sprintf('criteriaKey=%s has illegal prefix "my"', $criteriaKey));
+               } elseif (is_array($criteriaValue) || is_bool($criteriaValue) || is_object($criteriaValue) || is_resource($criteriaValue)) {
+                       // Throw UAE
+                       throw new UnexpectedValueException(sprintf('criteriaValue[]=%s is not accepted', gettype($criteriaValue)), FrameworkInterface::EXCEPTION_UNEXPECTED_VALUE);
+               }
+
                // Add it with generic method
-               $this->addCriteria($criteriaKey, $criteriaValue, 'exclude');
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-CRITERIA: Invoking this->addCriteria(%s,criteriaValue[]=%s,%s) ...', $criteriaKey, gettype($criteriaValue), Criteria::CRITERIA_TYPE_EXCLUDE));
+               $this->addCriteria($criteriaKey, $criteriaValue, Criteria::CRITERIA_TYPE_EXCLUDE);
+
+               // Trace message
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-CRITERIA: EXIT!');
        }
 
        /**
@@ -250,11 +429,38 @@ abstract class BaseCriteria extends BaseFrameworkSystem implements Criteria {
         * @param       $configEntry    Configuration entry
         * @param       $criteriaType   Type of this criteria, can be one of 'default' (default), 'choice' or 'exclude'
         * @return      void
+        * @throws      InvalidArgumentException        If a parameter is not valid
+        * @throws      UnexpectedValueException        If a parameter contains an unexpected/unsupported value
         */
-       public final function addConfiguredCriteria ($criteriaKey, $configEntry, $criteriaType = 'default') {
+       public final function addConfiguredCriteria (string $criteriaKey, string $configEntry, string $criteriaType = Criteria::CRITERIA_TYPE_DEFAULT) {
+               // Check parameter
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-CRITERIA: criteriaKey=%s,configEntry=%s,criteriaType=%s - CALLED!', strtoupper($criteriaType), $criteriaKey, $configEntry, $criteriaType));
+               if (empty($criteriaKey)) {
+                       // Throw IAE
+                       throw new InvalidArgumentException('Parameter "criteriaKey" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
+               } elseif ((strpos($criteriaKey, 'my-') !== false) || (strpos($criteriaKey, 'my_') !== false)) {
+                       // Throw it again
+                       throw new InvalidArgumentException(sprintf('criteriaKey=%s has illegal prefix "my"', $criteriaKey));
+               } elseif (empty($configEntry)) {
+                       // Throw it again
+                       throw new InvalidArgumentException('Parameter "configEntry" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
+               } elseif (empty($criteriaType)) {
+                       // Throw it again
+                       throw new InvalidArgumentException('Parameter "criteriaType" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
+               } elseif (!in_array($criteriaType, self::$CRITERIA_TYPES)) {
+                       // Throw it again
+                       throw new UnexpectedValueException(sprintf('criteriaType=%s is not supported', $criteriaType), FrameworkInterface::EXCEPTION_UNEXPECTED_VALUE);
+               }
+
                // Add the configuration entry as a criteria
-               $value = $this->getConfigInstance()->getConfigEntry($configEntry);
+               $value = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry($configEntry);
+
+               // Invoke inner method
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-CRITERIA: Invoking this->addCriteria(%s,value[%s]=%s,%s) ...', strtoupper($criteriaType), $criteriaKey, gettype($value), $value, $criteriaType));
                $this->addCriteria($criteriaKey, $value, $criteriaType);
+
+               // Trace message
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-CRITERIA: EXIT!', strtoupper($criteriaType)));
        }
 
        /**
@@ -263,33 +469,42 @@ abstract class BaseCriteria extends BaseFrameworkSystem implements Criteria {
         * @param       $criteriaKey    The requested criteria key
         * @param       $criteriaType   Type of this criteria, can be one of 'default' (default), 'choice' or 'exclude'
         * @return      $value                  Whether the value of the critera or false
+        * @throws      InvalidArgumentException        If a parameter is not valid
+        * @throws      UnexpectedValueException        If a parameter contains an unexpected/unsupported value
         */
-       public function getCriteriaElemnent ($criteriaKey, $criteriaType = 'default') {
-               // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($criteriaType) . '-CRITERIA[' . __METHOD__ . ':' . __LINE__ . ']: criteriaKey=' . $criteriaKey . ',criteriaType=' . $criteriaType . ' - CALLED!');
-
-               // Make sure no 'my-' or 'my_' passes this point
-               assert((strpos($criteriaKey, 'my-') === false) && (strpos($criteriaKey, 'my_') === false));
+       public function getCriteriaElemnent (string $criteriaKey, string $criteriaType = Criteria::CRITERIA_TYPE_DEFAULT) {
+               // Check parameter
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-CRITERIA: criteriaKey=%s,criteriaType=%s - CALLED!', strtoupper($criteriaType), $criteriaKey, $criteriaType));
+               if (empty($criteriaKey)) {
+                       // Throw IAE
+                       throw new InvalidArgumentException('Parameter "criteriaKey" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
+               } elseif ((strpos($criteriaKey, 'my-') !== false) || (strpos($criteriaKey, 'my_') !== false)) {
+                       // Throw it again
+                       throw new InvalidArgumentException(sprintf('criteriaKey=%s has illegal prefix "my"', $criteriaKey));
+               } elseif (empty($criteriaType)) {
+                       // Throw it again
+                       throw new InvalidArgumentException('Parameter "criteriaType" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
+               } elseif (!in_array($criteriaType, self::$CRITERIA_TYPES)) {
+                       // Throw it again
+                       throw new UnexpectedValueException(sprintf('criteriaType=%s is not supported', $criteriaType), FrameworkInterface::EXCEPTION_UNEXPECTED_VALUE);
+               }
 
                // Convert dashes to underscore
                $criteriaKey = StringUtils::convertDashesToUnderscores($criteriaKey);
 
-               // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($criteriaType) . '-CRITERIA[' . __METHOD__ . ':' . __LINE__ . ']: criteriaKey=' . $criteriaKey . ',criteria()=' . $this->countGenericArrayGroup('criteria', $criteriaType));
-
                // Default is not found
                $value = false;
 
                // Is the criteria there?
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('%s-CRITERIA: criteriaKey=%s,criteria()=%d', strtoupper($criteriaType), $criteriaKey, $this->countGenericArrayGroup('criteria', $criteriaType)));
                if ($this->isKeySet($criteriaType, $criteriaKey)) {
                        // Then use it
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-CRITERIA: Invoking this->getGenericArrayElement(criteria,%s,entries,%s) ...', strtoupper($criteriaType), $criteriaType, $criteriaKey));
                        $value = $this->getGenericArrayElement('criteria', $criteriaType, 'entries', $criteriaKey);
-               } // END - if
-
-               // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($criteriaType) . '-CRITERIA[' . __METHOD__ . ':' . __LINE__ . ']: value=' . $value . ' - EXIT!');
+               }
 
                // Return the value
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-CRITERIA: value[]=%s - EXIT!', strtoupper($criteriaType), gettype($value)));
                return $value;
        }
 
@@ -298,10 +513,22 @@ abstract class BaseCriteria extends BaseFrameworkSystem implements Criteria {
         *
         * @param       $criteriaKey    The requested criteria key
         * @return      $value                  Whether the value of the critera or false
+        * @throws      InvalidArgumentException        If a parameter is not valid
         */
-       public function getCriteriaChoiceElemnent ($criteriaKey) {
-               // Call inner method
-               return $this->getCriteriaElemnent($criteriaKey, 'choice');
+       public function getCriteriaChoiceElemnent (string $criteriaKey) {
+               // Check parameter
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-CRITERIA: criteriaKey=%s - CALLED!', $criteriaKey));
+               if (empty($criteriaKey)) {
+                       // Throw IAE
+                       throw new InvalidArgumentException('Parameter "criteriaKey" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
+               } elseif ((strpos($criteriaKey, 'my-') !== false) || (strpos($criteriaKey, 'my_') !== false)) {
+                       // Throw it again
+                       throw new InvalidArgumentException(sprintf('criteriaKey=%s has illegal prefix "my"', $criteriaKey));
+               }
+
+               // Invoke inner method
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-CRITERIA: Invoking this->getCriteriaElemnent(%s,%s) ...', $criteriaKey, Criteria::CRITERIA_TYPE_CHOICE));
+               return $this->getCriteriaElemnent($criteriaKey, Criteria::CRITERIA_TYPE_CHOICE);
        }
 
        /**
@@ -309,10 +536,22 @@ abstract class BaseCriteria extends BaseFrameworkSystem implements Criteria {
         *
         * @param       $criteriaKey    The requested criteria key
         * @return      $value                  Whether the value of the critera or false
+        * @throws      InvalidArgumentException        If a parameter is not valid
         */
-       public function getCriteriaExcludeElemnent ($criteriaKey) {
-               // Call inner method
-               return $this->getCriteriaElemnent($criteriaKey, 'exclude');
+       public function getCriteriaExcludeElemnent (string $criteriaKey) {
+               // Check parameter
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-CRITERIA: criteriaKey=%s - CALLED!', $criteriaKey));
+               if (empty($criteriaKey)) {
+                       // Throw IAE
+                       throw new InvalidArgumentException('Parameter "criteriaKey" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
+               } elseif ((strpos($criteriaKey, 'my-') !== false) || (strpos($criteriaKey, 'my_') !== false)) {
+                       // Throw it again
+                       throw new InvalidArgumentException(sprintf('criteriaKey=%s has illegal prefix "my"', $criteriaKey));
+               }
+
+               // Invoke inner method
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-CRITERIA: Invoking this->getCriteriaElemnent(%s,%s) ...', $criteriaKey, Criteria::CRITERIA_TYPE_EXCLUDE));
+               return $this->getCriteriaElemnent($criteriaKey, Criteria::CRITERIA_TYPE_EXCLUDE);
        }
 
        /**
@@ -321,40 +560,71 @@ abstract class BaseCriteria extends BaseFrameworkSystem implements Criteria {
         * @param       $entryArray             Array with the entries to find
         * @param       $criteriaType   Type of this criteria, can be one of 'default' (default), 'choice' or 'exclude'
         * @return      $matches                Whether the entry matches or not
+        * @throws      InvalidArgumentException        If a parameter is not valid
+        * @throws      UnexpectedValueException        If a parameter contains an unexpected/unsupported value
         */
-       public function ifEntryMatches (array $entryArray, $criteriaType = 'default') {
+       public function ifEntryMatches (array $entryArray, string $criteriaType = Criteria::CRITERIA_TYPE_DEFAULT) {
+               // Check parameters
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-CRITERIA: entryArray()=%d,criteriaType=%s - CALLED!', strtoupper($criteriaType), count($entryArray), $criteriaType));
+               if (count($entryArray) == 0) {
+                       // Throw IAE
+                       throw new InvalidArgumentException('entryArray cannot be an empty array');
+               } elseif (empty($criteriaType)) {
+                       // Throw it again
+                       throw new InvalidArgumentException('Parameter "criteriaType" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
+               } elseif (!in_array($criteriaType, self::$CRITERIA_TYPES)) {
+                       // Throw it again
+                       throw new UnexpectedValueException(sprintf('criteriaType=%s is not supported', $criteriaType), FrameworkInterface::EXCEPTION_UNEXPECTED_VALUE);
+               }
+
                // First nothing matches and nothing is counted
                $matches = false;
                $counted = 0;
 
                // Walk through all entries
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('%s-CRITERIA: Walking over entryArray()=%d ...', strtoupper($criteriaType), count($entryArray)));
                foreach ($entryArray as $key => $entry) {
                        // Make sure no 'my-' or 'my_' passes this point
-                       assert((strpos($key, 'my-') === false) && (strpos($key, 'my_') === false));
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('%s-CRITERIA: key=%s,entry[%s]=%s', strtoupper($criteriaType), $key, gettype($entry), $entry));
+                       if ((strpos($key, 'my-') !== false) || (strpos($key, 'my_') !== false)) {
+                               // Throw it again
+                               throw new InvalidArgumentException(sprintf('key=%s has illegal prefix "my"', $key));
+                       }
 
                        // Convert dashes to underscore
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-CRITERIA: Invoking StringUtils::convertDashesToUnderscores(%s) ...', strtoupper($criteriaType), $key));
                        $key = StringUtils::convertDashesToUnderscores($key);
 
                        // Then walk through all search criteria
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('%s-CRITERIA: key=%s - AFTER!', strtoupper($criteriaType), $key));
                        foreach ($this->getGenericArrayKey('criteria', $criteriaType, 'entries') as $criteriaKey => $criteriaValue) {
                                // Make sure no 'my-' or 'my_' passes this point
-                               assert((strpos($criteriaKey, 'my-') === false) && (strpos($criteriaKey, 'my_') === false) && (!is_bool($criteriaValue)));
+                               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('%s-CRITERIA: criteriaKey=%s,criteriaValue[%s]=%s', strtoupper($criteriaType), $criteriaKey, gettype($criteriaValue), $criteriaValue));
+                               if ((strpos($criteriaKey, 'my-') !== false) || (strpos($criteriaKey, 'my_') !== false)) {
+                                       // Throw it again
+                                       throw new UnexpectedValueException(sprintf('criteriaKey=%s has illegal prefix "my"', $criteriaKey), FrameworkInterface::EXCEPTION_UNEXPECTED_VALUE);
+                               }
 
                                // Convert dashes to underscore
+                               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-CRITERIA: Invoking StringUtils::convertDashesToUnderscores(%s) ...', strtoupper($criteriaType), $criteriaKey));
                                $criteriaKey = StringUtils::convertDashesToUnderscores($criteriaKey);
 
                                // Is the element found and does it match?
+                               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('%s-CRITERIA: key=%s,criteriaKey=%s', strtoupper($criteriaType), $key, $criteriaKey));
                                if (($key == $criteriaKey) && ($criteriaValue == $entry)) {
                                        // Then count this one up
+                                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('%s-CRITERIA: MATCHES!', strtoupper($criteriaType)));
                                        $counted++;
-                               } // END - if
-                       } // END - foreach
-               } // END - foreach
+                               }
+                       }
+               }
 
                // Now check if expected criteria counts match
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('%s-CRITERIA: counted=%d', strtoupper($criteriaType), $counted));
                $matches = ($counted == $this->countGenericArrayGroup('criteria', $criteriaType));
 
                // Return the result
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-CRITERIA: matches=%d - EXIT!', strtoupper($criteriaType), intval($matches)));
                return $matches;
        }
 
@@ -363,10 +633,19 @@ abstract class BaseCriteria extends BaseFrameworkSystem implements Criteria {
         *
         * @param       $entryArray             Array with the entries to find
         * @return      $matches                Whether the entry matches or not
+        * @throws      InvalidArgumentException        If a parameter is not valid
         */
        public function ifChoiceMatches (array $entryArray) {
-               // Call inner method
-               return $this->ifEntryMatches($entryArray, 'choice');
+               // Check parameter
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-CRITERIA: entryArray()=%d - CALLED!', count($entryArray)));
+               if (count($entryArray) == 0) {
+                       // Throw IAE
+                       throw new InvalidArgumentException('entryArray cannot be an empty array');
+               }
+
+               // Invoke inner method
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-CRITERIA: Invoking this->ifEntryMatches(%d,%s) ...', count($entryArray), Criteria::CRITERIA_TYPE_CHOICE));
+               return $this->ifEntryMatches($entryArray, Criteria::CRITERIA_TYPE_CHOICE);
        }
 
        /**
@@ -374,10 +653,19 @@ abstract class BaseCriteria extends BaseFrameworkSystem implements Criteria {
         *
         * @param       $entryArray             Array with the entries to find
         * @return      $matches                Whether the entry matches or not
+        * @throws      InvalidArgumentException        If a parameter is not valid
         */
        public function ifExcludeMatches (array $entryArray) {
-               // Call inner method
-               return $this->ifEntryMatches($entryArray, 'exclude');
+               // Check parameter
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-CRITERIA: entryArray()=%d - CALLED!', count($entryArray)));
+               if (count($entryArray) == 0) {
+                       // Throw IAE
+                       throw new InvalidArgumentException('entryArray cannot be an empty array');
+               }
+
+               // Invoke inner method
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-CRITERIA: Invoking this->ifEntryMatches(%d,%s) ...', count($entryArray), Criteria::CRITERIA_TYPE_EXCLUDE));
+               return $this->ifEntryMatches($entryArray, Criteria::CRITERIA_TYPE_EXCLUDE);
        }
 
        /**
@@ -386,13 +674,23 @@ abstract class BaseCriteria extends BaseFrameworkSystem implements Criteria {
         * @param       $onlyKeys       Only use these keys for a cache key
         * @param       $criteriaType   Type of this criteria, can be one of 'default' (default), 'choice' or 'exclude'
         * @return      $cacheKey       The key suitable for the cache system
+        * @throws      InvalidArgumentException        If a parameter is not valid
+        * @throws      UnexpectedValueException        If a parameter contains an unexpected/unsupported value
+        * @throws      BadMethodCallException  If this method is invoked before $criteriaType has been initialized
         */
-       public function getCacheKey ($onlyKeys = array(), $criteriaType = 'default') {
-               // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput($this->__toString() . ': criteriaType=' . $criteriaType . ',count()=' . $this->countGenericArray('criteria')));
-
-               // Make sure the criteria is there
-               assert($this->isValidGenericArrayGroup('criteria', $criteriaType));
+       public function getCacheKey (array $onlyKeys = [], string $criteriaType = Criteria::CRITERIA_TYPE_DEFAULT) {
+               // Check parameters
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-CRITERIA: onlyKeys()=%d,criteriaType=%s - CALLED!', strtoupper($criteriaType), count($onlyKeys), $criteriaType));
+               if (empty($criteriaType)) {
+                       // Throw it again
+                       throw new InvalidArgumentException('Parameter "criteriaType" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
+               } elseif (!in_array($criteriaType, self::$CRITERIA_TYPES)) {
+                       // Throw it again
+                       throw new UnexpectedValueException(sprintf('criteriaType=%s is not supported', $criteriaType), FrameworkInterface::EXCEPTION_UNEXPECTED_VALUE);
+               } elseif (!$this->isValidGenericArrayGroup('criteria', $criteriaType)) {
+                       // Not intialized yet
+                       throw new BadMethodCallException(sprintf('Method cannot be invoked before criteriaType=%s is initialized!', $criteriaType), FrameworkInterface::EXCEPTION_BAD_METHOD_CALL);
+               }
 
                // Initialize the key
                $cacheKey = '';
@@ -400,40 +698,50 @@ abstract class BaseCriteria extends BaseFrameworkSystem implements Criteria {
                // Now walk through all criterias
                foreach ($this->getGenericArrayKey('criteria', $criteriaType, 'entries') as $criteriaKey => $criteriaValue) {
                        // Make sure no 'my-' or 'my_' passes this point
-                       assert((strpos($criteriaKey, 'my-') === false) && (strpos($criteriaKey, 'my_') === false) && (!is_bool($criteriaValue)));
-
-                       // $criteriaValue cannot be an array
-                       assert(!is_array($criteriaValue));
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('%s-CRITERIA: criteriaKey=%s,criteriaValue[%s]=%s', strtoupper($criteriaType), $criteriaKey, gettype($criteriaValue), $criteriaValue));
+                       if ((strpos($criteriaKey, 'my-') !== false) || (strpos($criteriaKey, 'my_') !== false)) {
+                               // Throw UAE
+                               throw new UnexpectedValueException(sprintf('criteriaKey=%s has illegal prefix "my"', $criteriaKey), FrameworkInterface::EXCEPTION_UNEXPECTED_VALUE);
+                       } elseif (is_array($criteriaValue) || is_bool($criteriaValue) || is_object($criteriaValue) || is_resource($criteriaValue)) {
+                               // Throw it again
+                               throw new UnexpectedValueException(sprintf('criteriaValue[]=%s is not supported', gettype($criteriaValue)), FrameworkInterface::EXCEPTION_UNEXPECTED_VALUE);
+                       }
 
                        // Convert dashes to underscore
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-CRITERIA: Invoking StringUtils::convertDashesToUnderscores(%s) ...', strtoupper($criteriaType), $criteriaKey));
                        $criteriaKey = StringUtils::convertDashesToUnderscores($criteriaKey);
 
                        // Is the value in array or is $onlyKeys empty?
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('%s-CRITERIA: criteriaKey=%s', strtoupper($criteriaType), $criteriaKey));
                        if ((isset($onlyKeys[$criteriaKey])) || (count($onlyKeys) == 0)) {
                                // Add the value URL encoded to avoid any trouble with special characters
+                               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('%s-CRITERIA: Adding criteriaKey=%s,criteriaValue[%s]=%s to cache key ...', strtoupper($criteriaType), $criteriaKey, gettype($criteriaValue), $criteriaValue));
                                $cacheKey .= sprintf('%s=%s;',
                                        $criteriaKey,
                                        urlencode($criteriaValue)
                                );
-                       } // END - if
-               } // END - foreach
+                       }
+               }
 
                // Remove last semicolon
                $cacheKey = substr($cacheKey, 0, -1);
 
                // Is the instance SearchCriteria?
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('%s-CRITERIA: cacheKey=%s,this=%s', strtoupper($criteriaType), $cacheKey, $this->__toString()));
                if ($this instanceof SearchCriteria) {
                        // Check if 'limit' and 'skip' are in
                        if (((isset($onlyKeys['limit'])) && (isset($onlyKeys['skip']))) || (count($onlyKeys) == 0)) {
                                // Add limit and skip values
+                               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('%s-CRITERIA: Adding this->limit=%d,this->skip=%d to cache key ...', strtoupper($criteriaType), $this->getLimit(), $this->getSkip()));
                                $cacheKey .= sprintf(';%%limit%%=%s;%%skip%%=%s',
                                        $this->getLimit(),
                                        $this->getSkip()
                                );
-                       } // END - if
-               } // END - if
+                       }
+               }
 
                // Return the cache key
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-CRITERIA: cacheKey=%s - EXIT!', strtoupper($criteriaType), $cacheKey));
                return $cacheKey;
        }
 
@@ -443,9 +751,13 @@ abstract class BaseCriteria extends BaseFrameworkSystem implements Criteria {
         * @param       $onlyKeys       Only use these keys for a cache key
         * @return      $cacheKey       The key suitable for the cache system
         */
-       public function getCacheKeyChoice ($onlyKeys = array()) {
-               // Call inner method
-               return $this->getCacheKey($onlyKeys, 'choice');
+       public function getCacheKeyChoice (array $onlyKeys = []) {
+               // Trace message
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-CRITERIA: onlyKeys()=%d - CALLED!', count($onlyKeys)));
+
+               // Invoke inner method
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-CRITERIA: Invoking this->getCacheKey(onlyKeys()=%d,%s) ...', count($onlyKeys),Criteria::CRITERIA_TYPE_CHOICE));
+               return $this->getCacheKey($onlyKeys, Criteria::CRITERIA_TYPE_CHOICE);
        }
 
        /**
@@ -454,21 +766,13 @@ abstract class BaseCriteria extends BaseFrameworkSystem implements Criteria {
         * @param       $onlyKeys       Only use these keys for a cache key
         * @return      $cacheKey       The key suitable for the cache system
         */
-       public function getCacheKeyExclude ($onlyKeys = array()) {
-               // Call inner method
-               return $this->getCacheKey($onlyKeys, 'exclude');
-       }
+       public function getCacheKeyExclude (array $onlyKeys = []) {
+               // Trace message
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-CRITERIA: onlyKeys()=%d - CALLED!', count($onlyKeys)));
 
-       /**
-        * Count the criteria, e.g. useful to find out if a database query has no
-        * limitation (search criteria).
-        *
-        * @param       $criteriaType   Type of this criteria, can be one of 'default' (default), 'choice' or 'exclude'
-        * @return      $count  Count of all criteria entries
-        */
-       public final function count ($criteriaType = 'default') {
-               // Return it
-               return $this->countGenericArrayGroup('criteria', $criteriaType);
+               // Invoke inner method
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-CRITERIA: Invoking this->getCacheKey(onlyKeys()=%d,%s) ...', count($onlyKeys),Criteria::CRITERIA_TYPE_EXCLUDE));
+               return $this->getCacheKey($onlyKeys, Criteria::CRITERIA_TYPE_EXCLUDE);
        }
 
        /**
@@ -478,7 +782,9 @@ abstract class BaseCriteria extends BaseFrameworkSystem implements Criteria {
         * @return      $count  Count of all criteria entries
         */
        public final function countChoice () {
-               return $this->count('choice');
+               // Trace message
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-CRITERIA: CALLED!');
+               return $this->count(Criteria::CRITERIA_TYPE_CHOICE);
        }
 
        /**
@@ -488,7 +794,9 @@ abstract class BaseCriteria extends BaseFrameworkSystem implements Criteria {
         * @return      $count  Count of all criteria entries
         */
        public final function countExclude () {
-               return $this->count('exclude');
+               // Trace message
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-CRITERIA: CALLED!');
+               return $this->count(Criteria::CRITERIA_TYPE_EXCLUDE);
        }
 
 }