From b2693aba2c71d04c8c2488df6132f2f6cd03ae76 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sat, 25 Feb 2023 07:55:36 +0100 Subject: [PATCH] Continued: - commented out debug lines (very noisy) - added more debug lines --- .../dataset/class_DataSetCriteria.php | 24 ++-- .../criteria/search/class_SearchCriteria.php | 48 ++++---- .../criteria/update/class_UpdateCriteria.php | 4 +- .../classes/registry/class_BaseRegistry.php | 107 ++++++++++++++++-- 4 files changed, 133 insertions(+), 50 deletions(-) diff --git a/framework/main/classes/criteria/dataset/class_DataSetCriteria.php b/framework/main/classes/criteria/dataset/class_DataSetCriteria.php index c2a2bb24..b2ec49eb 100644 --- a/framework/main/classes/criteria/dataset/class_DataSetCriteria.php +++ b/framework/main/classes/criteria/dataset/class_DataSetCriteria.php @@ -80,7 +80,7 @@ class DataSetCriteria extends BaseCriteria implements StoreableCriteria { */ public static final function createDataSetCriteria (string $tableName) { // Validate parameter - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('DATA-SET-CRITERIA: tableName=%s - CALLED!', $tableName)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('DATA-SET-CRITERIA: tableName=%s - CALLED!', $tableName)); if (empty($tableName)) { // Throw IAE throw new InvalidArgumentException('Parameter "tableName" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); @@ -93,7 +93,7 @@ class DataSetCriteria extends BaseCriteria implements StoreableCriteria { $criteriaInstance->setTableName($tableName); // Return the instance - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('DATA-SET-CRITERIA: criteriaInstance=%s - EXIT!', $criteriaInstance->__toString())); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('DATA-SET-CRITERIA: criteriaInstance=%s - EXIT!', $criteriaInstance->__toString())); return $criteriaInstance; } @@ -192,7 +192,7 @@ class DataSetCriteria extends BaseCriteria implements StoreableCriteria { */ public final function getUniqueValue () { // Get primary key(s) first - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('DATA-SET-CRITERIA: CALLED!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('DATA-SET-CRITERIA: CALLED!'); $primaryKey = trim($this->getCriteriaElemnent($this->getPrimaryKey())); $primaryKeys = $this->getPrimaryKeys(); @@ -200,7 +200,7 @@ class DataSetCriteria extends BaseCriteria implements StoreableCriteria { * If this is not set, this could mean a badly written frontend as * tables should always have a primary key. */ - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('DATA-SET-CRITERIA: this->tableName=%s,primaryKey=%s,primaryKeys()=%d', $this->getTableName(), $primaryKey, count($primaryKeys))); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('DATA-SET-CRITERIA: this->tableName=%s,primaryKey=%s,primaryKeys()=%d', $this->getTableName(), $primaryKey, count($primaryKeys))); if (count($primaryKeys) > 0) { /* * Init return value, this can be put all together without any @@ -212,18 +212,18 @@ class DataSetCriteria extends BaseCriteria implements StoreableCriteria { // Combination set, so get all foreach ($primaryKeys as $primaryKeyPart) { // Add it - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('DATA-SET-CRITERIA: primaryKeyPart=%s', $primaryKeyPart)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('DATA-SET-CRITERIA: primaryKeyPart=%s', $primaryKeyPart)); $return .= trim($this->getCriteriaElemnent($primaryKeyPart)); } // Debug message // Return it - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('DATA-SET-CRITERIA: return=%s - EXIT!', $return)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('DATA-SET-CRITERIA: return=%s - EXIT!', $return)); return $return; } elseif (!empty($primaryKey)) { // Return primary key - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('DATA-SET-CRITERIA: primaryKey=%s - EXIT!', $primaryKey)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('DATA-SET-CRITERIA: primaryKey=%s - EXIT!', $primaryKey)); return $primaryKey; } else { // Issue a warning @@ -233,14 +233,14 @@ class DataSetCriteria extends BaseCriteria implements StoreableCriteria { $uniqueKey = trim($this->getCriteriaElemnent($this->getUniqueKey())); // Is it empty, too? - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('DATA-SET-CRITERIA: uniqueKey=%s', $uniqueKey)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('DATA-SET-CRITERIA: uniqueKey=%s', $uniqueKey)); if (empty($uniqueKey)) { // Bad news, nothing is "unique" by design for this table throw new BadMethodCallException(sprintf('Table %s has both no primary and unique key, but %s was called. Please fix your table.', $this->getTableName(), __METHOD__), FrameworkInterface::EXCEPTION_BAD_METHOD_CALL); } // Return unique key - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('DATA-SET-CRITERIA: uniqueKey=%s - EXIT!', $uniqueKey)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('DATA-SET-CRITERIA: uniqueKey=%s - EXIT!', $uniqueKey)); return $uniqueKey; } } @@ -252,18 +252,18 @@ class DataSetCriteria extends BaseCriteria implements StoreableCriteria { */ public final function getPrimaryKey () { // Get primary key by default - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('DATA-SET-CRITERIA: CALLED!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('DATA-SET-CRITERIA: CALLED!'); $primaryKey = $this->primaryKey; // Is it still empty? - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('DATA-SET-CRITERIA: primaryKey=%s', $primaryKey)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('DATA-SET-CRITERIA: primaryKey=%s', $primaryKey)); if (empty($primaryKey)) { // Get uniqueKey $primaryKey = $this->getUniqueKey(); } // Return it - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('DATA-SET-CRITERIA: primaryKey=%s - EXIT!', $primaryKey)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('DATA-SET-CRITERIA: primaryKey=%s - EXIT!', $primaryKey)); return $primaryKey; } diff --git a/framework/main/classes/criteria/search/class_SearchCriteria.php b/framework/main/classes/criteria/search/class_SearchCriteria.php index d1c8c91c..1880919c 100644 --- a/framework/main/classes/criteria/search/class_SearchCriteria.php +++ b/framework/main/classes/criteria/search/class_SearchCriteria.php @@ -69,11 +69,11 @@ class SearchCriteria extends BaseCriteria implements LocalSearchCriteria { */ public static final function createSearchCriteria () { // Get a new instance - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('SEARCH-CRITERIA: CALLED!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('SEARCH-CRITERIA: CALLED!'); $criteriaInstance = new SearchCriteria(); // Return this instance - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('SEARCH-CRITERIA: criteriaInstance=%s - EXIT!', $criteriaInstance->__toString())); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('SEARCH-CRITERIA: criteriaInstance=%s - EXIT!', $criteriaInstance->__toString())); return $criteriaInstance; } @@ -97,7 +97,7 @@ class SearchCriteria extends BaseCriteria implements LocalSearchCriteria { */ public final function setConfiguredLimit (string $configKey) { // Check parameter - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('SEARCH-CRITERIA: configKey=%s - CALLED!', $configKey)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('SEARCH-CRITERIA: configKey=%s - CALLED!', $configKey)); if (empty($configKey)) { // Throw IAE throw new InvalidArgumentException('Parameter "configKey" is empty'); @@ -107,11 +107,11 @@ class SearchCriteria extends BaseCriteria implements LocalSearchCriteria { $limit = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry($configKey); // And set it - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('SEARCH-CRITERIA: limit=%d', $limit)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('SEARCH-CRITERIA: limit=%d', $limit)); $this->setLimit($limit); // Trace message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('SEARCH-CRITERIA: EXIT!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('SEARCH-CRITERIA: EXIT!'); } /** @@ -156,7 +156,7 @@ class SearchCriteria extends BaseCriteria implements LocalSearchCriteria { */ public function isCriteriaMatching (string $key, $value, string $separator = ',') { // $key/$value cannot be array/NULL/bool, value can be NULL but then NULL must be loocked for - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('SEARCH-CRITERIA: key=%s,value[]=%s,separator=%s - CALLED!', $key, gettype($value), $separator)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('SEARCH-CRITERIA: key=%s,value[]=%s,separator=%s - CALLED!', $key, gettype($value), $separator)); if (empty($key)) { // Throw IAE throw new InvalidArgumentException('Parameter "key" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); @@ -169,16 +169,16 @@ class SearchCriteria extends BaseCriteria implements LocalSearchCriteria { } // "Explode" value - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('SEARCH-CRITERIA: Invoking explode("%s",value[]=%s) ...', $separator, gettype($value))); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('SEARCH-CRITERIA: Invoking explode("%s",value[]=%s) ...', $separator, gettype($value))); $valueArray = explode($separator, $value); - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('SEARCH-CRITERIA: valueArray()=%d', count($valueArray))); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('SEARCH-CRITERIA: valueArray()=%d', count($valueArray))); // Get 'default' search value - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('SEARCH-CRITERIA: Invoking this->getCriteriaElemnent(%s) ...', $key)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('SEARCH-CRITERIA: Invoking this->getCriteriaElemnent(%s) ...', $key)); $searchDefault = $this->getCriteriaElemnent($key); // 'default' check - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('SEARCH-CRITERIA: searchDefault[%s]=%s', gettype($searchDefault), $searchDefault)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('SEARCH-CRITERIA: searchDefault[%s]=%s', gettype($searchDefault), $searchDefault)); $isMatching = ( ( ( @@ -194,58 +194,58 @@ class SearchCriteria extends BaseCriteria implements LocalSearchCriteria { ); // Get 'choice' search value (can be NULL or $separator-separated string) - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('SEARCH-CRITERIA: isMatching=%d', intval($isMatching))); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('SEARCH-CRITERIA: isMatching=%d', intval($isMatching))); $searchChoice = $this->getCriteriaChoiceElemnent($key); // Is an array returned? - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('SEARCH-CRITERIA: searchChoice[]=%s', gettype($searchChoice))); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('SEARCH-CRITERIA: searchChoice[]=%s', gettype($searchChoice))); if (!is_array($searchChoice) && !is_bool($searchChoice)) { // Should not happen throw new UnexpectedValueException(sprintf('searchChoice[]=%s is unexpected', gettype($searchChoice)), FrameworkInterface::EXCEPTION_UNEXPECTED_VALUE); } // 'choice' check - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('SEARCH-CRITERIA: searchChoice[]=%s', gettype($searchChoice))); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('SEARCH-CRITERIA: searchChoice[]=%s', gettype($searchChoice))); if ((is_array($searchChoice)) && (count($valueArray) == 1)) { // $value is a single-search value, so use in_[] $isMatching = ((($isMatching === true) || (($searchDefault === false) && (!is_null($value)))) && (in_array($value, $searchChoice))); // Debug message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('SEARCH-CRITERIA: isMatching=%d - SINGLE-MATCH', intval($isMatching))); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('SEARCH-CRITERIA: isMatching=%d - SINGLE-MATCH', intval($isMatching))); } elseif ((is_array($searchChoice)) && (count($valueArray) > 1)) { // $value is choice-search value, so check all entries - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('SEARCH-CRITERIA: searchChoice()=%d,valueArray()=%d - MULTI-MATCH', count($searchChoice), count($valueArray))); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('SEARCH-CRITERIA: searchChoice()=%d,valueArray()=%d - MULTI-MATCH', count($searchChoice), count($valueArray))); $isMatching = (($isMatching === true) || (($searchDefault === false) && (!is_null($value)))); // Loop through all values - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('SEARCH-CRITERIA: isMatching=%d - BEFORE!', intval($isMatching))); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('SEARCH-CRITERIA: isMatching=%d - BEFORE!', intval($isMatching))); foreach ($valueArray as $idx => $match) { // Is it found? (one is okay) - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('SEARCH-CRITERIA: idx=%d,match=%s', $idx, $match)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('SEARCH-CRITERIA: idx=%d,match=%s', $idx, $match)); $isMatching = (($isMatching === true) && (in_array($match, $searchChoice))); // No longer matching? - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('SEARCH-CRITERIA: isMatching=%d - LOOP!', intval($isMatching))); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('SEARCH-CRITERIA: isMatching=%d - LOOP!', intval($isMatching))); if (!$isMatching) { // Skip further iterations - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage('SEARCH-CRITERIA: BREAK!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage('SEARCH-CRITERIA: BREAK!'); break; } } // Debug message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('SEARCH-CRITERIA: isMatching=%d - AFTER!', intval($isMatching))); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('SEARCH-CRITERIA: isMatching=%d - AFTER!', intval($isMatching))); } else { // Choice-match is false - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('SEARCH-CRITERIA: key=%s[],searchChoice[]=%s,value[%s]=%s,isMatching=%d - FALSE-MATCH', $key, gettype($searchChoice), gettype($value), $value, intval($isMatching))); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('SEARCH-CRITERIA: key=%s[],searchChoice[]=%s,value[%s]=%s,isMatching=%d - FALSE-MATCH', $key, gettype($searchChoice), gettype($value), $value, intval($isMatching))); } // Get 'exclude' search value - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('SEARCH-CRITERIA: Invoking this->getCriteriaExcludeElemnent(%s) ...', $key)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('SEARCH-CRITERIA: Invoking this->getCriteriaExcludeElemnent(%s) ...', $key)); $searchExclude = $this->getCriteriaExcludeElemnent($key); // 'exclude' check - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('SEARCH-CRITERIA: searchExclude[%s]=%s', gettype($searchExclude), $searchExclude)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('SEARCH-CRITERIA: searchExclude[%s]=%s', gettype($searchExclude), $searchExclude)); $isMatching = ( ( ( @@ -267,7 +267,7 @@ class SearchCriteria extends BaseCriteria implements LocalSearchCriteria { ); // Return result - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('SEARCH-CRITERIA: isMatching=%d - EXIT!', intval($isMatching))); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('SEARCH-CRITERIA: isMatching=%d - EXIT!', intval($isMatching))); return $isMatching; } diff --git a/framework/main/classes/criteria/update/class_UpdateCriteria.php b/framework/main/classes/criteria/update/class_UpdateCriteria.php index 238055e8..f177543c 100644 --- a/framework/main/classes/criteria/update/class_UpdateCriteria.php +++ b/framework/main/classes/criteria/update/class_UpdateCriteria.php @@ -54,11 +54,11 @@ class UpdateCriteria extends BaseCriteria implements LocalUpdateCriteria { */ public static final function createUpdateCriteria () { // Get a new instance - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('UPDATE-CRITERIA: CALLED!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('UPDATE-CRITERIA: CALLED!'); $criteriaInstance = new UpdateCriteria(); // Return this instance - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('SEARCH-CRITERIA: criteriaInstance=%s - EXIT!', $criteriaInstance->__toString())); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('SEARCH-CRITERIA: criteriaInstance=%s - EXIT!', $criteriaInstance->__toString())); return $criteriaInstance; } diff --git a/framework/main/classes/registry/class_BaseRegistry.php b/framework/main/classes/registry/class_BaseRegistry.php index bac576c9..a309efda 100644 --- a/framework/main/classes/registry/class_BaseRegistry.php +++ b/framework/main/classes/registry/class_BaseRegistry.php @@ -12,6 +12,7 @@ use Org\Mxchange\CoreFramework\Traits\Iterator\IteratorTrait; // Import SPL stuff use \InvalidArgumentExeption; use \IteratorAggregate; +use \UnexpectedValueException; /** * A general Registry @@ -52,11 +53,15 @@ abstract class BaseRegistry extends BaseFrameworkSystem implements Register, Reg */ protected function __construct (string $className) { // Call parent constructor + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-REGISTRY: className=%s - CONSTRUCTED!', $className)); parent::__construct($className); // Init generic arrays $this->initGenericArrayGroup('registry', 'generic'); $this->initGenericArrayGroup('registry', 'instance'); + + // Trace message + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-REGISTRY: EXIT!'); } /** @@ -66,22 +71,26 @@ abstract class BaseRegistry extends BaseFrameworkSystem implements Register, Reg * @return $iteratorInstance An instance of a Iterator class */ public function getIterator (array $onlyRegistries = []) { + // Get iterator + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-REGISTRY: onlyRegistries()=%d - CALLED!', count($onlyRegistries))); + $iteratorInstance = $this->getIteratorInstance(); + // Is it set? - if (is_null($this->getIteratorInstance())) { + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-REGISTRY: iteratorInstance[]=%s', gettype($iteratorInstance))); + if (is_null($iteratorInstance)) { // Then instance it $iteratorInstance = ObjectFactory::createObjectByConfiguredName('registry_iterator_class', [$this]); // ... and set it here $this->setIteratorInstance($iteratorInstance); - } else { - // Use set iterator - $iteratorInstance = $this->getIteratorInstance(); } // Init iterator instance + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-REGISTRY: Invoking iteratorInstance->initIterator(onlyRegistries()=%d) ...', count($onlyRegistries))); $iteratorInstance->initIterator($onlyRegistries); // Return it + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-REGISTRY: iteratorInstance=%s - EXIT!', $iteratorInstance->__toString())); return $iteratorInstance; } @@ -90,12 +99,22 @@ abstract class BaseRegistry extends BaseFrameworkSystem implements Register, Reg * * @param $instanceKey The key holding an instance in registry * @return $exists Whether the key exists in registry + * @throws InvalidArgumentException If a paramter has an invalid value */ public function instanceExists (string $instanceKey) { + // Check parameter + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-REGISTRY: instanceKey=%s - CALLED!', $instanceKey)); + if (empty($instanceKey)) { + // Throw IAE + throw new InvalidArgumentException('Parameter "instanceKey" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); + } + // Does this key exists? + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-REGISTRY: Invoking this->isGenericArrayKeySet(registry, instance, %s) ...', $instanceKey)); $exists = $this->isGenericArrayKeySet('registry', 'instance', $instanceKey); // Return the result + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-REGISTRY: exists=%d - EXIT!', intval($exists))); return $exists; } @@ -105,9 +124,10 @@ abstract class BaseRegistry extends BaseFrameworkSystem implements Register, Reg * @param $instanceKey The key to identify the instance * @param $objectInstance An instance we shall store * @return void + * @throws InvalidArgumentException If a paramter has an invalid value */ public function addInstance (string $instanceKey, Registerable $objectInstance) { - // Validate parameter + // Check parameter /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-REGISTRY: instanceKey=%s,objectInstance=%s - CALLED!', $instanceKey, $objectInstance->__toString())); if (empty($instanceKey)) { // Throw IAE @@ -147,10 +167,22 @@ abstract class BaseRegistry extends BaseFrameworkSystem implements Register, Reg * @param $key The key to identify the whole list * @param $value The value to be stored * @return void + * @throws InvalidArgumentException If a paramter has an invalid value */ public final function addEntry (string $key, $value) { + // Check parameter + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-REGISTRY: key=%s,value[]=%s - CALLED!', $key, gettype($value))); + if (empty($key)) { + // Throw IAE + throw new InvalidArgumentExeption('Parameter "key" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); + } + // Push it + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-REGISTRY: Invoking this->pushValueToGenericArrayKey(registry,generic,%s,value[]=%s) ...', $key, gettype($value))); $this->pushValueToGenericArrayKey('registry', 'generic', $key, $value); + + // Trace message + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-REGISTRY: EXIT!'); } /** @@ -158,18 +190,30 @@ abstract class BaseRegistry extends BaseFrameworkSystem implements Register, Reg * * @param $key Key * @return $entries An array with entries from this registry + * @throws InvalidArgumentException If a paramter has an invalid value */ public final function getEntries (string $key = NULL) { + // Check parameter + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-REGISTRY: key=%s,value[]=%s - CALLED!', $key, gettype($value))); + if (!is_null($key) && empty($key)) { + // Throw IAE + throw new InvalidArgumentExeption('Parameter "key" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); + } + // Default is whole array + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-REGISTRY: Invoking this->getGenericArray(registry) ...'); $entries = $this->getGenericArray('registry'); // Is $key set? + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-REGISTRY: key[]=%s,entries()=%d', $key, count($entries))); if (!is_null($key)) { // Then use this entry + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-REGISTRY: Invoking this->getGenericArrayKey(registry,generic,%s) ...', $key)); $entries = $this->getGenericArrayKey('registry', 'generic', $key); } // Return the array + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-REGISTRY: entries()=%d - EXIT!', count($entries))); return $entries; } @@ -179,32 +223,48 @@ abstract class BaseRegistry extends BaseFrameworkSystem implements Register, Reg * @param $arrayKey The array (key) to look in * @param $lookFor The key to look for * @return $entry An array with all keys + * @throws InvalidArgumentException If a paramter has an invalid value + * @throws UnexpectedValueException If $value3 is not an array */ public function getArrayFromKey (string $arrayKey, string $lookFor) { + // Check parameter + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-REGISTRY: arrayKey=%s,lookFor=%s - CALLED!', $arrayKey, $lookFor)); + if (empty($arrayKey)) { + // Throw IAE + throw new InvalidArgumentExeption('Parameter "arrayKey" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); + } elseif (empty($lookFor)) { + // Throw IAE + throw new InvalidArgumentExeption('Parameter "lookFor" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); + } + // Init array $entry = []; // "Walk" over all entries - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('REGISTRY: Checking arrayKey=' . $arrayKey . ',lookFor=' . $lookFor); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-REGISTRY: Checking arrayKey=%s,lookFor=%s', $arrayKey, $lookFor)); foreach ($this->getEntries($arrayKey) as $key => $value) { // If $value matches the $lookFor, we need to look for more entries for this! - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('REGISTRY: Checking key=' . $key . ',value=' . $value . ',lookFor=' . $lookFor); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-REGISTRY: Checking key=%s,value=%s,lookFor=%s', $key, $value, $lookFor)); if ($lookFor == $value) { // Look for more entries foreach ($this->getEntries() as $key2 => $value2) { // Now "walk" through all entries, if an array is returned + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-REGISTRY: key2=%s,value2[]=%s', $key2, gettype($value2))); if (is_array($value2)) { // "Walk" through all of them - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('REGISTRY: Checking key2=' . $key2 . ',value2()=' . count($value2) . ',lookFor=' . $lookFor); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-REGISTRY: Checking key2=%s,value2()=%s,lookFor=%s', $key2, count($value2), $lookFor)); foreach ($value2 as $key3 => $value3) { // $value3 needs to be an array - assert(is_array($value3)); + if (!is_array($value3)) { + // Throw exception + throw new UnexpectedValueException(sprintf('arrayKey=%s,key=%s,value=%s,key2=%s,key3=%s has unexpected value3[]=%s', $arrayKey, $key, $value, $key2, $key3, gettype($value3)), FrameworkInterface::EXCEPTION_UNEXPECTED_VALUE); + } // Both keys must match! - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('REGISTRY: Checking key=' . $key . ',key3=' . $key3 . ',isset()=' . isset($value3[$key]) . ' ...'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-REGISTRY: Checking key=%s,key3=%s,isset()=%s ...', $key, $key3, intval(isset($value3[$key])))); if (($key == $key3) || (isset($value3[$key]))) { // Then add it - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('REGISTRY: Adding ' . $value3[$key] . ' ...'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-REGISTRY: Adding value3[%s]=%s ...', $key, $value3[$key])); $entry[$key3] = $value3[$key]; } } @@ -212,12 +272,13 @@ abstract class BaseRegistry extends BaseFrameworkSystem implements Register, Reg } // Skip further lookups + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage('BASE-REGISTRY: BREAK!'); break; } } // Return it - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('REGISTRY: Returning entry(' . count($entry) . ')=' . print_r($entry, true)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-REGISTRY: entry()=%d - EXIT!', count($entry))); return $entry; } @@ -226,19 +287,30 @@ abstract class BaseRegistry extends BaseFrameworkSystem implements Register, Reg * * @param $instanceKey The key to identify the instance * @return $objectInstance An instance we shall store + * @throws InvalidArgumentException If a paramter has an invalid value * @throws NullPointerException If the requested key is not found */ public function getInstance (string $instanceKey) { + // Check parameter + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-REGISTRY: instanceKey=%s - CALLED!', $instanceKey)); + if (empty($instanceKey)) { + // Throw IAE + throw new InvalidArgumentException('Parameter "instanceKey" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); + } + // Is the instance there? + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-REGISTRY: Invoking this->instanceExists(%s) ...', $instanceKey)); if (!$this->instanceExists($instanceKey)) { // This might happen if a non-registered key was requested throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); } // Get the instance + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-REGISTRY: Invoking this->getGenericArrayKey(registry,instance,%s) ...', $instanceKey)); $objectInstance = $this->getGenericArrayKey('registry', 'instance', $instanceKey); // Return the result + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-REGISTRY: objectInstance=%s - EXIT!', $objectInstance->__toString())); return $objectInstance; } @@ -252,10 +324,21 @@ abstract class BaseRegistry extends BaseFrameworkSystem implements Register, Reg * @return $registryKey A registry key */ public static function getRegistryKeyFromArray (string $prefix, array $data) { + // Check parameter + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-REGISTRY: prefix=%s,data()=%d - CALLED!', $prefix, count($data))); + if (empty($prefix)) { + // Throw IAE + throw new InvalidArgumentException('Parameter "prefix" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); + } elseif (count($data) == 0) { + // Throw IAE + throw new InvalidArgumentException('Parameter "data" is an empty array', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); + } + // "Generate" the key $registryKey = $prefix . self::REGISTRY_KEY_GLUE . implode(self::REGISTRY_KEY_GLUE, $data); // Return it + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-REGISTRY: registryKey=%s - EXIT!', $registryKey)); return $registryKey; } -- 2.39.5