function addConfiguredCriteria ($criteriaKey, $configEntry, $criteriaType = 'default');
/**
- * Get criteria element or null if not found
+ * Get criteria element or FALSE if not found
*
* @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 null
+ * @return $value Whether the value of the critera or FALSE
*/
function getCriteriaElemnent ($criteriaKey, $criteriaType = 'default');
/**
- * Get criteria element or null if not found for 'choice' type
+ * Get criteria element or FALSE if not found for 'choice' type
*
* @param $criteriaKey The requested criteria key
- * @return $value Whether the value of the critera or null
+ * @return $value Whether the value of the critera or FALSE
*/
function getCriteriaChoiceElemnent ($criteriaKey);
/**
- * Get criteria element or null if not found for 'exclude' type
+ * Get criteria element or FALSE if not found for 'exclude' type
*
* @param $criteriaKey The requested criteria key
- * @return $value Whether the value of the critera or null
+ * @return $value Whether the value of the critera or FALSE
*/
function getCriteriaExcludeElemnent ($criteriaKey);
$applicationInstance = $this->getResolverInstance()->getApplicationInstance();
// Get a RNG instance (Random Number Generator)
- // @TODO Rewrite this code to make use of generateRandomString() from 'hub' project
$rngInstance = ObjectFactory::createObjectByConfiguredName('rng_class');
// Generate a pseudo-random string
*/
public final function addCriteria ($criteriaKey, $criteriaValue, $criteriaType = 'default') {
// Make sure no 'my-' or 'my_' passes this point
- assert((strpos($criteriaKey, 'my-') === FALSE) && (strpos($criteriaKey, 'my_') === FALSE));
+ assert((strpos($criteriaKey, 'my-') === FALSE) && (strpos($criteriaKey, 'my_') === FALSE) && (!is_bool($criteriaValue)));
// Convert dashes to underscore
$criteriaKey = $this->convertDashesToUnderscores($criteriaKey);
*/
public final function addChoiceCriteria ($criteriaKey, $criteriaValue) {
// Make sure no 'my-' or 'my_' passes this point
- assert((strpos($criteriaKey, 'my-') === FALSE) && (strpos($criteriaKey, 'my_') === FALSE));
+ assert((strpos($criteriaKey, 'my-') === FALSE) && (strpos($criteriaKey, 'my_') === FALSE) && (!is_bool($criteriaValue)));
// Debug message
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(strtoupper($criteriaType) . '(' . $this->__toString() . ')-CRITERIA[' . __LINE__ . ']: criteriaKey=' . $criteriaKey . ',criteriaValue=' . $criteriaValue);
}
/**
- * Get criteria element or null if not found
+ * Get criteria element or FALSE if not found
*
* @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 null
+ * @return $value Whether the value of the critera or FALSE
*/
public function getCriteriaElemnent ($criteriaKey, $criteriaType = 'default') {
// Make sure no 'my-' or 'my_' passes this point
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(strtoupper($criteriaType) . '-CRITERIA[' . __LINE__ . ']: criteriaKey=' . $criteriaKey . ',criteria()=' . count($this->criteria[$criteriaType]));
// Default is not found
- $value = NULL;
+ $value = FALSE;
// Is the criteria there?
if ($this->isKeySet($criteriaType, $criteriaKey)) {
}
/**
- * Get criteria element or null if not found for 'choice' type
+ * Get criteria element or FALSE if not found for 'choice' type
*
* @param $criteriaKey The requested criteria key
- * @return $value Whether the value of the critera or null
+ * @return $value Whether the value of the critera or FALSE
*/
public function getCriteriaChoiceElemnent ($criteriaKey) {
// Call inner method
}
/**
- * Get criteria element or null if not found for 'exclude' type
+ * Get criteria element or FALSE if not found for 'exclude' type
*
* @param $criteriaKey The requested criteria key
- * @return $value Whether the value of the critera or null
+ * @return $value Whether the value of the critera or FALSE
*/
public function getCriteriaExcludeElemnent ($criteriaKey) {
// Call inner method
// Then walk through all search criteria
foreach ($this->criteria[$criteriaType] as $criteriaKey => $criteriaValue) {
// Make sure no 'my-' or 'my_' passes this point
- assert((strpos($criteriaKey, 'my-') === FALSE) && (strpos($criteriaKey, 'my_') === FALSE));
+ assert((strpos($criteriaKey, 'my-') === FALSE) && (strpos($criteriaKey, 'my_') === FALSE) && (!is_bool($criteriaValue)));
// Convert dashes to underscore
$criteriaKey = $this->convertDashesToUnderscores($criteriaKey);
// Now walk through all criterias
foreach ($this->criteria[$criteriaType] as $criteriaKey => $criteriaValue) {
// Make sure no 'my-' or 'my_' passes this point
- assert((strpos($criteriaKey, 'my-') === FALSE) && (strpos($criteriaKey, 'my_') === FALSE));
+ assert((strpos($criteriaKey, 'my-') === FALSE) && (strpos($criteriaKey, 'my_') === FALSE) && (!is_bool($criteriaValue)));
// Convert dashes to underscore
$criteriaKey = $this->convertDashesToUnderscores($criteriaKey);
* @return $isMatching Whether the key/value is matching or excluded
*/
public function isCriteriaMatching ($key, $value, $separator = ',') {
- // $value cannot be array
- assert(!is_array($value));
+ // $key/$value cannot be array/NULL/bool, value can be NULL but then NULL must be loocked for
+ assert((!is_array($value)) && (!is_bool($value)) && (!is_array($key)) && (!is_null($key)) && (!is_bool($key)));
// "Explode" value
$valueArray = explode($separator, $value);
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SEARCH-CRITERIA[' . __LINE__ . ']: key=' . $key . ',value=' . $value . ' - ENTERED!');
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SEARCH-CRITERIA[' . __LINE__ . ']: key=' . $key . ',value[' . gettype($value) . ']=' . $value . ' - ENTERED!');
// Get 'default' search value
$searchDefault = $this->getCriteriaElemnent($key);
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SEARCH-CRITERIA[' . __LINE__ . ']: getCriteriaElement(' . $key . ')[' . gettype($searchDefault) . ']=' . $searchDefault);
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SEARCH-CRITERIA[' . __LINE__ . ']: getCriteriaElement(' . $key . ')[' . gettype($searchDefault) . ']=' . $searchDefault);
// 'default' check
- $isMatching = ((!is_null($searchDefault)) && ($searchDefault == $value));
+ $isMatching = (((($searchDefault !== FALSE) && ($searchDefault == $value)) || ((is_null($searchDefault)) && (is_null($value)))) || ($searchDefault === FALSE));
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SEARCH-CRITERIA[' . __LINE__ . ']: getCriteriaElement(' . $key . ')[' . gettype($searchDefault) . ']=' . $searchDefault . ',isMatching=' . intval($isMatching));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SEARCH-CRITERIA[' . __LINE__ . ']: getCriteriaElement(' . $key . ')[' . gettype($searchDefault) . ']=' . $searchDefault . ',isMatching=' . intval($isMatching));
// Get 'choice' search value (can be NULL or $separator-separated string)
$searchChoice = $this->getCriteriaChoiceElemnent($key);
+ // May be FALSE or array
+ assert(($searchChoice === FALSE) || (is_array($searchChoice)));
+
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SEARCH-CRITERIA[' . __LINE__ . ']: getCriteriaChoiceElement(' . $key . ')[' . gettype($searchChoice) . ']=' . print_r($searchChoice, TRUE));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SEARCH-CRITERIA[' . __LINE__ . ']: getCriteriaChoiceElement(' . $key . ')[' . gettype($searchChoice) . ']=' . print_r($searchChoice, TRUE));
// 'choice' check
if ((is_array($searchChoice)) && (count($valueArray) == 1)) {
// $value is a single-search value, so use in_array()
- $isMatching = ((($isMatching === TRUE) || (is_null($searchDefault))) && ((is_null($searchChoice)) || ((is_array($searchChoice)) && (in_array($value, $searchChoice)))));
+ $isMatching = ((($isMatching === TRUE) || (($searchDefault === FALSE) && (!is_null($value)))) && (in_array($value, $searchChoice)));
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SEARCH-CRITERIA[' . __LINE__ . ']: getCriteriaChoiceElement(' . $key . ')[]=' . gettype($searchChoice) . ',value=' . $value . ',isMatching=' . intval($isMatching) . ' - SINGLE-MATCH');
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SEARCH-CRITERIA[' . __LINE__ . ']: getCriteriaChoiceElement(' . $key . ')[]=' . gettype($searchChoice) . ',value[' . gettype($value) . ']=' . $value . ',isMatching=' . intval($isMatching) . ' - SINGLE-MATCH');
} elseif ((is_array($searchChoice)) && (count($valueArray) > 1)) {
+ // Debug message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SEARCH-CRITERIA[' . __LINE__ . ']: getCriteriaChoiceElement(' . $key . ')[]=' . gettype($searchChoice) . ',valueArray()=' . count($valueArray) . ',isMatching=' . intval($isMatching));
+
// $value is choice-search value, so check all entries
- $isMatching = ((is_null($searchDefault)) || ($isMatching === TRUE));
+ $isMatching = (($isMatching === TRUE) || (($searchDefault === FALSE) && (!is_null($value))));
$idx = 0;
foreach ($valueArray as $idx => $match) {
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SEARCH-CRITERIA[' . __LINE__ . ']: match=' . $match . ',count(searchChoice)=' . count($searchChoice));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SEARCH-CRITERIA[' . __LINE__ . ']: match=' . $match . ',count(searchChoice)=' . count($searchChoice));
// Is it found? (one is okay)
$isMatching = (($isMatching === TRUE) && (in_array($match, $searchChoice)));
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SEARCH-CRITERIA[' . __LINE__ . ']: match=' . $match . ',isMatching=' . intval($isMatching));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SEARCH-CRITERIA[' . __LINE__ . ']: match=' . $match . ',isMatching=' . intval($isMatching));
} // END - foreach
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SEARCH-CRITERIA[' . __LINE__ . ']: getCriteriaChoiceElement(' . $key . ')[]=' . gettype($searchChoice) . ',valueArray()=' . count($valueArray) . ',idx=' . $idx . ',isMatching=' . intval($isMatching) . ' - CHOICE-MATCH');
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SEARCH-CRITERIA[' . __LINE__ . ']: getCriteriaChoiceElement(' . $key . ')[]=' . gettype($searchChoice) . ',valueArray()=' . count($valueArray) . ',idx=' . $idx . ',isMatching=' . intval($isMatching) . ' - CHOICE-MATCH');
} else {
- // Choice-match is NULL?
- $isMatching = (($isMatching === TRUE) || (is_null($searchDefault)));
-
+ // Choice-match is FALSE
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SEARCH-CRITERIA[' . __LINE__ . ']: getCriteriaChoiceElement(' . $key . ')[]=' . gettype($searchChoice) . ',value=' . $value . ',isMatching=' . intval($isMatching) . ' - NULL-MATCH');
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SEARCH-CRITERIA[' . __LINE__ . ']: getCriteriaChoiceElement(' . $key . ')[]=' . gettype($searchChoice) . ',value[' . gettype($value) . ']=' . $value . ',isMatching=' . intval($isMatching) . ' - FALSE-MATCH');
}
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SEARCH-CRITERIA[' . __LINE__ . ']: getCriteriaChoiceElement(' . $key . ')[]=' . gettype($searchChoice) . ',isMatching=' . intval($isMatching));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SEARCH-CRITERIA[' . __LINE__ . ']: getCriteriaChoiceElement(' . $key . ')[]=' . gettype($searchChoice) . ',isMatching=' . intval($isMatching));
// Get 'exclude' search value
$searchExclude = $this->getCriteriaExcludeElemnent($key);
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SEARCH-CRITERIA[' . __LINE__ . ']: getCriteriaExcludeElement(' . $key . ')[' . gettype($searchExclude) . ']=' . $searchExclude);
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SEARCH-CRITERIA[' . __LINE__ . ']: getCriteriaExcludeElement(' . $key . ')[' . gettype($searchExclude) . ']=' . $searchExclude);
// 'exclude' check
- $isMatching = (((is_null($searchChoice)) || ($isMatching === TRUE)) && (!is_null($searchExclude)) && ($searchExclude != $value));
+ $isMatching = (
+ (
+ (
+ $isMatching === TRUE
+ ) && (
+ $searchExclude === FALSE
+ )
+ ) || (
+ (
+ (
+ $isMatching === TRUE
+ ) && (
+ $searchExclude !== FALSE
+ ) && (
+ $searchExclude !== $value
+ )
+ )
+ )
+ );
// Return result
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SEARCH-CRITERIA[' . __LINE__ . ']: key=' . $key . ',value=' . $value . ',isMatching=' . intval($isMatching) . ' - EXIT!');
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SEARCH-CRITERIA[' . __LINE__ . ']: key=' . $key . ',value[' . gettype($value) . ']=' . $value . ',isMatching=' . intval($isMatching) . ' - EXIT!');
return $isMatching;
}
}
// Search in the criteria with FMFW (First Matches, First Wins)
foreach ($dataArray as $key => $value) {
+ // Make sure value is not bool
+ assert(!is_bool($value));
+
// Found one entry?
$isFound = (($isFound === TRUE) && ($searchInstance->isCriteriaMatching($key, $value)));
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE: key=' . $key . ',value=' . $value . ',isFound=' . intval($isFound));
// Search in the criteria with FMFW (First Matches, First Wins)
foreach ($dataArray as $key => $value) {
+ // Make sure value is not bool
+ assert(!is_bool($value));
+
// Found one entry?
$isFound = (($isFound === TRUE) && ($searchInstance->isCriteriaMatching($key, $value)));
} // END - foreach
// Entry found, so update it
foreach ($searchArray as $searchKey => $searchValue) {
+ // Make sure the value is not bool again
+ assert(!is_bool($searchValue));
+
+ // Debug message + add/update it
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE: criteriaKey=' . $searchKey . ',criteriaValue=' . $searchValue);
$dataArray[$searchKey] = $searchValue;
} // END - foreach